quick
quick copied to clipboard
IDEA: Implicit Method When Relationship Entities Loaded
There are lots of great interception methods and implicit methods that trigger when entities load or pre/post saving.
I think it would be great to expand on this idea when it comes to relationships. What would you think of adding a new method that would fire when a relationship/child entity is loaded? Additionally, we could even take advantage of onMissingMethod()
to dynamically create the method name based on the relationship.
Why would this be helpful? Sometimes child objects need a reference to parent entities, and this could be handled at runtime with something like this:
// Media.cfc
component
extends="quick.models.BaseEntity"
accessors="true"
{
// Relationships
function mediaSizes() {
function hasMany( "MediaSize" );
}
// Call to implicit method when relationship entity is loaded
function mediaSizesLoaded( entity ) {
// set a reference to the parent
entity.setMedia( this );
}
}