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!
I updated
Permission.cfc
to show a different approach. This leverages implicit accessors (this.invokeImplicitAccessor = true;
inApplication.cfc
) and caching. Callingpermission.roles
will first fire off to theRoleService
and cache the result for future calls. The query builder idea is interesting, but not really fleshed out in ColdBox that I know of.