Skip to content

CakePHP 3.0.0RC2 when baking to a plugin, bake controller doesn't find model's associations. #57

@djamesfar

Description

@djamesfar

To reproduce:
bake a plugin:

bin\cake bake plugin Pluggy

bake a model in the plugin, where the table has belongsTo or hasMany associations (ie Roles):

bin\cake bake model --plugin Pluggy --no-test --force roles
bin\cake bake model --plugin Pluggy --no-test --force users

now bake the UsersController:

bin\cake bake controller --plugin Pluggy --no-test --force users

Check the UsersController::add() method and you won't see the find for the associated belongsTo table:

$roles = $this->Users->Roles->find('list',...etc)     <--- *this is missing*

so it doesn't set(compact('roles'.. for the view.

If you take out the --plugin Pluggy, it will work correctly, creating the controller in src/controller, of course, not in plugins/Pluggy/src/controller.

I dug around a little in the add.ctp element template used by the controller template and inserted some debug logging after the $associations array is populated using Bake->aliasExtractor (around line 36), and it shows the array empty when baking to a plugin, filled if not. I didn't dig into the source for this aliasExtractor, but somewhere I expect a $plugin variable got left out.
DJ

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions