Baptiste ROUSSEL Sat May 28 08:48:49 -0400 2011

Subject: Associations => through

i have a little problem with the use of through in associations.
I have a correct link with has_many on a direct way, but i fail to use a has_many with through...

I worked on a simple study case : an user can have multiple projects.
So we have the following models :

The first foreach is running well and i have the list but i link manually the three models.
The second fail and since this morning i did not find why... I read a lot of help topic to find another guy with the same problem but did not found a valid answer to solve my problem.

Actual Exception :

Fatal error: Uncaught exception 'ActiveRecord\HasManyThroughAssociationException'
 with message 'Could not find the association userstoproject in model user'
 in C:\wamp\www\test\lib\php-activerecord-20110425\lib\Relationship.php:491 
Stack trace: 
#0 C:\wamp\www\test\lib\php-activerecord-20110425\lib\Model.php(485): ActiveRecord\HasMany->load(Object(user)) 
#1 C:\wamp\www\test\lib\php-activerecord-20110425\lib\Model.php(333): ActiveRecord\Model->read_attribute('projects2') 
#2 C:\wamp\www\test\test.php(57): ActiveRecord\Model->__get('projects2') 
#3 {main} thrown in C:\wamp\www\test\lib\php-activerecord-20110425\lib\Relationship.php on line 491

PS: i did not use camelName because i fail more with them... x)
Maybe i will use them later when i will manage more this orm.

Regards, xTG.

Yoan B Sun May 29 16:18:49 -0400 2011

Try to RTFM :-)

through matches a relation name, not a class name.

Baptiste ROUSSEL Thu Jun 02 05:45:50 -0400 2011

The fault to my bad english.... :<

Thanks to linking the anchor. :)

Yoan B Thu Jun 02 19:20:40 -0400 2011

Pas de problème Baptiste, une fois que tu as pigé le truc c'est simple, jusque là il faut essayer/tester/…

Bonne continuation,

Baptiste ROUSSEL Sat Jun 04 08:52:24 -0400 2011

Tout à fait l'esprit oui. Le tout est que ça m'énerve un peu ce genre de souci...
Je l'avais lu et relue cette page, mais pas forcement au bon paragraphe. Et ma lecture est beaucoup trop approximative quand je survole...

Yoan B Sat Jun 04 08:54:19 -0400 2011

Le plus simple (à mes yeux) est d'aller fouiner dans lib/Relationships.php pour comprendre comment ça fonctionne à coup de var_dump.