We are looking at adding DataMapper ORM into our Code Igniter HMVC setup.
DataMapper looks very cool, but I noticed that the models are all tightly coupled with the has_one
and has_many
E.g. from the datamapper docs:
class User extends DataMapper {
var $has_many = array('book');
var $has_one = array('country');
........
class Country extends DataMapper {
var $table = 'countries';
var $has_many = array('user');
........
class Book extends DataMapper {
var $has_many = array('user');
As I mentioned at the start, we are using HMVC to deal with modulized code. This means that we may have the countries module, and/or we may have the books module. but they are modulized, so the users module (which includes the User object) doesn't know that the other two modules exist so we can't specify in the User
model the information about the other two models.
Now the other two models depend on the users module, so they know it exists, What I was thinking is that in the Country model we could append book
to the User has_many
array?
Is this the right way to do this? I imagine datamapper must have a way to handle these use cases?