This is a proof-of-concept for relationships without using an ORM in ColdFusion (specifically, ColdBox — you can replace "wirebox" with your favorite DI framework).
The API I'm trying to get is borrowed from Laravel. We are not using an ORM, though, and have traditionally handled the requests using a {Object}Service -> {Object}DAO -> {Object} pattern. This is my attempt to create the nice relationship syntax found in Laravel for our non-ORM stack.
Things I want to keep:
- the great syntax:
user.roles()
- the fact that the related objects are not created unless called
- not having to call a different method or pass a different parameter to the service to compose the relationships
- (though, if you have a strong opinion about that, I'm interested in at least hearing why)
I'd love comments on this. I'm trying to learn the best way to accomplish this given our stack.
Thanks!
So it seems like one big downside of this approach is the lack of caching on models. Looking into Eloquent, it makes a distinction between
user.roles()
anduser.roles
. The first returns a scoped query and the second returns the collection. Also, the second will cache the result on the parent model.