Added fix to allow pivots to use classes on attach#120
Conversation
|
Doesn't that require a bit more unit tests before merging? |
|
@LukeTowers @jaxwilko Any explanation for this? |
|
I agree - that's a bit of a behaviour change for the event there. |
|
Hmm, I had thought that event was one of the recently added ones, although it looks like it has been around for a while, so I'll need to fix that. |
|
@bennothommo @mjauvin is this better: e6e3c5b? |
|
@LukeTowers much better! |
|
Thanks for checking in on this guys :) |
|
I just wanted to report after pulling in the latest commit from winter/storm the following code no longer works for me: $model->bindEvent('model.relation.afterAttach', function (string $relationName, array $attachedIDList, array $insertData) use ($model) {
// ...
}Error: The relation it's failing on is a Reverting back to commit 5c46aa3 allows my code to work again. |
|
@ericp-mrel can you toss a |
|
I think you'd have to use |
|
Good point @ericp-mrel, I had forgotten that they weren't associative arrays. Since you reported the issue and tested the fix do you want to submit it as a PR to count towards Hacktoberfest for you? |
|
@LukeTowers I can submit a PR, but one thing I'm really curious about why is the event signature different for custom pivot model vs non-custom pivot model? I guess I'm not sure why they need to be different for event purposes and wish I knew the reason for changing it. |
…ator. (#122) This fixes the issue with the arrays not being merged properly with auto-incremented keys. See #120 (comment)
|
@ericp-mrel because the code that inserts the data with custom pivot models uses the unmodified values passed to the method and the code that inserts directly into the table uses the processed variables. Unfortunately when the events were originally added they were passed the processed variables instead of the raw ones, so we can't use just the raw variables for backwards compatibility reasons |

This PR ports some functionality from Laravel to allow for pivot models to be used during an attach call.
This means that events can now be processed on pivot models during the attach process.