kla/php-activerecord — Issue #174: Associated Models should inherit current model namespace by default?
Author: jchook
Created: 2011-10-23 22:43:45+00:00
State: open

It is likely that associated models will fall into the same namespace on larger projects, so why not detect the namespace of the current model and use that as the default namespace when instantiating associated model classes.

For (untested pseudo-code) example.
```php
namespace MyApp;

class Alpha extends \ActiveRecord\Model {
static $has_one = array(array('beta'));
}

class Beta extends \ActiveRecord\Model {
static $belongs_to = array(array('alpha'));
}

$alpha = Alpha::find(1);
$alpha->beta; // Cannot find class \Beta
```

I have looked into making this change myself, but the association design makes it very difficult.

Say associations are made between a "left" and a "right" model. IMO, a proper association routine has access to both of these model objects at the time of association.

In php-activerecord, the association routine can only readily access the "right" model. I'm not sure of a clean way to access the "left" model object to see what its namespace is.

So, right now my only option is to manually specify the class on every association.