Is it possible to set a property on a model on insert that is inbetween two hasManyToMany relationship?

Lets say that I'm using Robots, RobotParts and Parts from the documentation. I would like to be able to set an additional property in RobotParts when I'm creating the relationship.

So when I automatically create the intermeddiate table with the following it would be possible to pass in a value to RobotParts to fill in a custom field.

// This only appears to be able to populate RobotParts with two keys and not another value. 
$robot->parts = $part;

Not sure about passing a value but beforeValidationOnCreate may be a way to go.



44.7k

I extended Model::save and am manually firing a custom event after the save and then a Behavior is querying to see if there is an existing relationship and if one does not exist then it creates one. I need to be able to manually set the relation and also auto generate one. The issue that I have with doing it in any standard event is that it is impossible to check if a relationship has been set because calling the alias when it has not been defined will cause it to not be saveable. The act of checking ensures that a default set later on will not be saved. Probably this could be improved and might be considered a bug.