[eluser]prestondocks[/eluser]
HI,
I am wanting to make my models more independent of each other while still using DMZ. The idea being that I would like to drop in new models, without having to update the current models to define new relationships.
My idea is to put in the construct of the new model a line the uses array push to define the other side of the relationship.
So I have a User model that already exists and it has the following relationships defined.
Code:
class User extends DataMapper
{
//Relationship properties
var $has_one = array('profile');
var $has_many = array();
...
//Setter function to extend the has_many relationship
public function set_has_many($class_name)
{
array_push($this->has_many,$class_name);
}
}
I now want to create a new model called Task it will look like
Code:
class Task extends DataMapper
{
//Relationship properties
var $has_one = array('user');
var $has_many = array();
function __construct()
{
parent::__construct();
//This code tells the user model that it now has a relationship to task
$this->load->model('user');
User::set_has_many('task');
}
}
For some reason this is not working. The has_many property is being updated, as I can echo it to the screen and see the added array element.
I am wondering if when my call to set_has_many() takes place that DataMapper has already grabbed the values of the properties and changing them has no effect.
Can anyone confirm if it is possible to do this in some other way?
Thanks
Simon