lox / pheasant

A lightweight data mapper designed to take advantage of PHP 5.3+
http://getpheasant.com
MIT License
101 stars 21 forks source link

DomainObject methods not accessible when using `includes()` #131

Closed bjornpost closed 9 years ago

bjornpost commented 9 years ago

When using includes(), methods defined on the included DomainObjects are not accessible. For example:

$foo = \Model\Foo::findById(1)->includes(array('Bar'))->first();
var_dump($foo->Bar); // works
var_dump($foo->Bar->myMethod()); // throws error, method is accessible again when removing includes()

Seems like an undocumented regression. Right now ArrayCache::add() adds $object->toArray(), but it should add the entire $object. Will create PR.

/cc @Jud

Jud commented 9 years ago

@bjornpost ah, this is what I was thinking about when I mentioned memcached in #130. Like you pointed out, not calling ->toArray will work for a local array cache, but, if using something like memcached you'd either need DomainObjects to be serializable (unfortunately not possible #76), or call toArray and hydrate on read.

I'm not sure it matters right now, because the hypothetical memcached pheasant cache doesn't exist, but that's where my head's at.

bjornpost commented 9 years ago

Fixed in 594dba8.