Jelmer Schreuder Sun Jan 23 00:03:11 -0500 2011

Subject: Through relationship with custom classname?

I'm trying to intergrate php.activerecord with FuelPHP and I'm pretty succesfull up till now. There's one issue I'm running into: The models are in a namespace and I'm not following conventions. The through-model's name is Base\Model_User_RelUserGroup and it's table is "users_groups", I get the following error however: "ReflectionException [ -1 ]: Class UserGroup does not exist" when I use the following code:

$user = Base\Model_User::find('first');
exit(print_r($user->groups));

Here's the code of the 3 models: http://scrp.at/sh

I tried to find the relevant lines of code and I ran into line 475 of relationships.php which doesn't seem to be conditional or use anything I set in the through-relationship's options:

$through_table = Table::load(classify($this->through, true));

Edit: forgot to mention, the Base\Model class is just a simple extension of ActiveRecord\Model with an empty static method _init() that is needed in order not to confuse our autoloader.


Jacques Fuentes Sat Feb 05 17:01:20 -0500 2011

Are you using the latest nightly or stable? There were some issues with relationships and using class_name that I addressed a month ago or so.

Jelmer Schreuder Sat Feb 05 22:25:17 -0500 2011

Already tried that, but the line I pointed out causes this (#478 in 1/17 nightly).

I solved it for myself, probably not good enough for inclusion or I'd have made a pull-request. I haven't tested the hasmany relations well enough to know if this won't cause other problems.

Here's my diff for the changes I made to get this to work: http://scrp.at/u3

Matthew Machuga Sat Feb 12 13:51:04 -0500 2011

Jelmer,

Glad to see you're already working on integration for Fuel. Not that I have anything against the standard AR package, I just really prefer PHPAR and was probably going to bork something along the way while integrating it myself :)

Jelmer Schreuder Sat Feb 12 13:55:00 -0500 2011

Matthew,

It's already available on https://github.com/fuel-packages/fuel-phpactiverecord
Or you can install it using oil:

php oil package install phpactiverecord

I haven't included the above fix though and I'll only update that with stable releases.

Matthew Machuga Mon Feb 14 10:17:58 -0500 2011

Awesome! Thanks :)

Michiel van Leening Mon Mar 07 16:33:46 -0500 2011

Hi Jelmer,

You fixed a problem i also had. Your diff @ http://scrp.at/u3 saved my day! I had legacy tables with dutch foreign keys which i can't change but wanted to switch to english named models... Works like a charm now, although i have some funky $has_many arrays :-)

Wheee - Dutchmen unite!

I'm posting some pasties for anyone facing the same problem (me in the future!). php: http://pastie.org/1644857 sql: http://pastie.org/1644861

Cheers!

(1-6/6)