Log message #4051056

# At Username Text
# 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
# Jul 12th 2017, 13:48 kim____ I have a behavior that logs the creation of an entity to a LogsTable. The new log needs a reference to the new entity. So I created an afterSave for the behavior that saves the log. But i get a "Source entity needs to be persisted before proceeding" message. Shouldn't the new entity exist already?
# Jul 12th 2017, 12:41 clementcrown @casmo, thanks it worksin the .htaccess
# Jul 12th 2017, 12:39 clementcrown @casmo, thanks, let me try that
# Jul 12th 2017, 12:35 casmo I'm not sure. Maybe you can try .htaccess? https://stackoverflow.com/questions/949415/overriding-upload-max-filesize