# |
Jul 12th 2017, 14:22 |
jeremyharris |
glad to hear |
# |
Jul 12th 2017, 14:22 |
kim____ |
@jeremyharris the beforeSave worked... thanks! |
# |
Jul 12th 2017, 14:22 |
neon1024 |
https://github.com/cakephp/bake/blob/master/src/View/Helper/BakeHelper.php#L109 |
# |
Jul 12th 2017, 14:22 |
kim____ |
@jeremyharris. |
# |
Jul 12th 2017, 14:21 |
neon1024 |
@josexato It can read the association from the table instance, https://github.com/cakephp/bake/blob/master/src/Template/Bake/Element/Controller/edit.ctp#L16-L17 |
# |
Jul 12th 2017, 14:21 |
josexato |
Hello, one quick question how does bake recognize if the realationship is hasone or belongs to? |
# |
Jul 12th 2017, 14:20 |
jeremyharris |
I’ll say one more time: I suggest you use beforeSave to add the newActivity on the entity, so it will be saved in one transaction and linked automatically |
# |
Jul 12th 2017, 14:19 |
kim____ |
but let me try your beforeSave suggestion. |
# |
Jul 12th 2017, 14:19 |
kim____ |
source entity needs to be persisted before proceeding. |
# |
Jul 12th 2017, 14:19 |
kim____ |
same error |
# |
Jul 12th 2017, 14:19 |
kim____ |
let me try |
# |
Jul 12th 2017, 14:18 |
jeremyharris |
$this->Table->belongsToMany(‘Activities’)->link($entity, [$newActivity]); |
# |
Jul 12th 2017, 14:18 |
jeremyharris |
wait |
# |
Jul 12th 2017, 14:17 |
jeremyharris |
ok, I think you want line 12 on your gist to be this: $this->Table->belongsToMany(‘Activities’)->link($newActivity, [$entity]); |
# |
Jul 12th 2017, 14:17 |
kim____ |
but let me try. |
# |
Jul 12th 2017, 14:17 |
kim____ |
if i do that. won't it give an error because the newActivity is not yet created? |
# |
Jul 12th 2017, 14:16 |
jeremyharris |
oh* |
# |
Jul 12th 2017, 14:16 |
jeremyharris |
or, so the problem is link |
# |
Jul 12th 2017, 14:16 |
kim____ |
but not in the join table; |
# |
Jul 12th 2017, 14:16 |
jeremyharris |
I think this is more complicated than it needs to be. It doesn’t look like afterSave is doing anything special from what you pasted, you could just add the entity in beforeSave and it would hook up the foreignKeys and link it automatically |
# |
Jul 12th 2017, 14:16 |
kim____ |
when i look at my database tables. the lead entity is saved as well as the activity |
# |
Jul 12th 2017, 14:14 |
jeremyharris |
well this is weird, why does the Activity have an id at that point in time? I’m really confused here |
# |
Jul 12th 2017, 14:14 |
kim____ |
where can i get the stack trace? |
# |
Jul 12th 2017, 14:11 |
kim____ |
sorry mate. |
# |
Jul 12th 2017, 14:11 |
kim____ |
https://gist.github.com/mccp/82c28fc7f3bd0b1ff9d97452f6863029 |
# |
Jul 12th 2017, 14:10 |
jeremyharris |
while you’re at it, can you gist the full stack trace of the error? |
# |
Jul 12th 2017, 14:09 |
jeremyharris |
it is “created” at that point, just not persisted into the database (“saved”) yet |
# |
Jul 12th 2017, 14:09 |
jeremyharris |
what about debug($newEntity) at line 8, here: https://gist.github.com/mccp/9c96c20d1890a477761ef96919acb2c3#file-aftersave_inside_behavior-L8 |
# |
Jul 12th 2017, 14:08 |
kim____ |
but doesn't get to that point because $entity is not yet saved. |
# |
Jul 12th 2017, 14:08 |
kim____ |
afterSave is the place where it will be created. |
# |
Jul 12th 2017, 14:07 |
kim____ |
but inside the afterSave, newActivity is not yet created. |
# |
Jul 12th 2017, 14:07 |
kim____ |
https://gist.github.com/mccp/e613e639beb517811e893bec626b3fdc |
# |
Jul 12th 2017, 14:06 |
kim____ |
oh, sorry hold on |
# |
Jul 12th 2017, 14:05 |
jeremyharris |
ok sorry, I think I’m not being clear. Can you gist the output of debug($entity) and debug($newActivity) from the afterSave method on your behavior? I need to see their state at the time that afterSave is called, to see if there are validation errors, to see if the entities were created successfully, etc. |
# |
Jul 12th 2017, 14:03 |
kim____ |
https://gist.github.com/mccp/0f67df8b3af80268baa53749b582fa07 |
# |
Jul 12th 2017, 14:02 |
jeremyharris |
I want to see what afterSave is getting |
# |
Jul 12th 2017, 14:02 |
jeremyharris |
> can you please gist the entity as well as the newActivity entity you gisted the tables :slightly_smiling_face: |
# |
Jul 12th 2017, 14:01 |
kim____ |
that's why i need it in afterSave |
# |
Jul 12th 2017, 14:01 |
kim____ |
newActivity can't be created without the newEntity |
# |
Jul 12th 2017, 14:01 |
kim____ |
https://gist.github.com/mccp/b6a01403bc47d08bdd4fd5be03dd43e7 |
# |
Jul 12th 2017, 13:59 |
jeremyharris |
(I’m just trying to understand your use case) |