Skip to content

Fixing a bug that appears when trying to bake plugin models#303

Merged
markstory merged 2 commits intocakephp:masterfrom
burzum:bug/getTableObject
Jan 31, 2017
Merged

Fixing a bug that appears when trying to bake plugin models#303
markstory merged 2 commits intocakephp:masterfrom
burzum:bug/getTableObject

Conversation

@burzum
Copy link
Copy Markdown

@burzum burzum commented Jan 29, 2017

This fixes a problem that happens when you already have an existing model of the same name in your app but want to bake one of the same name in your plugin. I've used as well the --table option. My main app is using an users table, now for a plugin I wanted to bake a Users model that is using the wp_users table from another DB. This was not possible without this change.

Tried this:

.\bin\cake bake model Users --table wp_fk_users -c wordpress -p Burzum/WpFrontend

Resulting in:

Error: [Cake\Database\Exception] SQLSTATE[42S02]: Base table or view not found: 1146 Table 'wordpressfk.users' doesn't exist

This fixes a problem that happens when you already have an existing model in your app but want to bake one of the same name in your plugin. I've used as well the --table option. My main app is using an users table, now for a plugin I wanted to bake a Users model that is using the wp_users table from another DB. This was not possible without this change.
@codecov-io
Copy link
Copy Markdown

codecov-io commented Jan 29, 2017

Codecov Report

Merging #303 into master will increase coverage by <.01%.

@@            Coverage Diff             @@
##           master     #303      +/-   ##
==========================================
+ Coverage   95.76%   95.77%   +<.01%     
==========================================
  Files          23       23              
  Lines        1866     1869       +3     
==========================================
+ Hits         1787     1790       +3     
  Misses         79       79
Impacted Files Coverage Δ
src/Shell/Task/ModelTask.php 94.92% <100%> (+0.03%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 28d9a67...9ac53c0. Read the comment docs.

{
$plugin = $this->param('plugin');
if (!empty($plugin)) {
$className = $plugin . '.' . $className;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any way we could get a test for this?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you tell me how? All I know is that testing console stuff is pain in the ass. :(

Copy link
Copy Markdown
Member

@dereuromark dereuromark Jan 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could unit test the getTableObject() here. Mock the rest away.

@markstory markstory merged commit 24ef0cc into cakephp:master Jan 31, 2017
@markstory markstory added this to the 1.2.x milestone Jan 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants