# |
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) |
# |
Jul 12th 2017, 13:58 |
jeremyharris |
e.g., on beforeSave add $entity->activities = [$newActivity] |
# |
Jul 12th 2017, 13:57 |
jeremyharris |
again, is there a reason you don’t simply add the entity on before save so it’s all saved in a single transaction? |
# |
Jul 12th 2017, 13:57 |
jeremyharris |
can you please gist the entity as well as the newActivity entity |
# |
Jul 12th 2017, 13:56 |
kim____ |
this is the contents of afterSave |
# |
Jul 12th 2017, 13:56 |
kim____ |
https://gist.github.com/mccp/9c96c20d1890a477761ef96919acb2c3 |
# |
Jul 12th 2017, 13:55 |
kim____ |
the afterSave is implemented inside a behavior. |
# |
Jul 12th 2017, 13:52 |
jeremyharris |
can you gist some information, such as the entity that afterSave gets. Is there a reason you aren’t using the ORM’s relationships and just adding the log to the entity on beforeSave? |
# |
Jul 12th 2017, 13:51 |
kim____ |
still the same problem |
# |
Jul 12th 2017, 13:51 |
kim____ |
i also tried to change afterSave to afterSaveCommit |