I'm in the process of building a plugin that includes a behavior and several related models. My goal is to make this as easy as possible for the developer using the behavior. My perfect world has the dev simply attaching the behavior to any relevant models and configuring it.
The behavior interacts directly with one of the models and a hasOne
association is being created on the fly, b开发者_如何学运维ut the other models contain supporting data that is important. What I'd like to do is to have that model pull in its related data by modifying the Containable
models.
In short:
MyModel
(whichactsAs
the behavior) gets bound to top level model during the behavior's setup method.- The supporting models are directly associated to the top level model
- In
MyBehavior::beforeFind
, I'd like to ensure that supporting model data is returned without the user having to know to ask for it when callingMyModel::find( ... )
.
I haven't found the right keys that will allow me to modify these things at runtime. Maybe it's not even possible given that I want to essentially interact with another behavior (Containable
).
Any thoughts would be appreciated.
This code automatically adds some contains to the find before it is run, you just have to make sure that your behavior is attached before the containable behavior or it will not work. The beforeFind callback for a behavior is only run once, so once containable has been called adding something like this does nothing. Took me a while to get it going because of that.
https://github.com/infinitas/infinitas/blob/dev/core/contents/models/behaviors/contentable.php#L65
精彩评论