Hi / Salut!
One way of doing that is to give the full namespace to class_name, it gets repetitive but you should manage that.
static $has_many = array(
array('users', 'classe_name' => 'app\\models\\User')
);
Yes, PHP-AR has some trouble with relations and so, but they can be fixed. As I'm using this too I manage to fix some (not all of them yet).
Try to use the version from github and report bugs there too.
Hi Yoan Blanc, thanks for your reply
i have tried but that cause some issues with `has_many through`.
Hi,
This is the branch I did some work on this: https://github.com/greut/php-activerecord/tree/gh101-has_many-through
And it seems that it has been integrated as the tests are now part of kla's repository: https://github.com/kla/php-activerecord/blob/master/test/HasManyThroughTest.php
Add yours if you find anything that isn't working as expected.
Don't work if you named the `through association` `users_newsletters` (note the 'S' on users).
With my modification on ` ActiveRecord\HasMany::load()`, it work fine.
The other suggestions are for facility. Why repeat all class names while "Inflector" works well and in most time namespace will be the same for all classes ?
(sorry again for my bad English)
On va passer en céfran (sorry guys) :
Est-ce que tu arriverais à écrire un test simple sur comment tu aimerais que ça fonctionne ?
Oui c'est chiant d'avoir à répéter le class_name à chaque fois, c'est clair. Il y aurait de quoi regarder dans le même namespace que la classe définie également. Ça semble être intéressant et ne limite pas autrement ce qu'il est possible de faire. Et `through` doit aller rechercher la relation du même nom et non assumer qu'il y a une classe nommée de la même manière.
C'est un peu le merdier, mais on devrait réussir à pondre un truc solide si on s'y met à plusieurs. Ils ne sont pas hyper réactif sur GH mais une fois toutes les deux semaines, l'un deux se réveille. Pas terrible…
Hi,
I've made an issue and wrote a patch too. Try it, fix the tests, and continue the discussion other there.
• https://github.com/kla/php-activerecord/issues/135
• https://gist.github.com/889432
--
Salut,
J'ai tenté une approche où le système va aller rechercher la classe dans l'espace de nom courant si la classe dans l'espace de nom global n'existe pas. Je te laisse tester ça et commenter sur github directement. J'ai eu la flemme de faire une branche.
• https://github.com/kla/php-activerecord/issues/135
• https://gist.github.com/889432
Work "like a charm", must be implemented in the next nightly !
Milles merci Yoan ;)
Are there plans to implement this change? I spent quite a bit of time being really confused because of what I think is a namespace issue. The activerecord_autoload was duplicating the namespace in the path and failing to load. By adding $class_name = ActiveRecord\denamespace($class_name); that seems to fix it but I don't know enough about namespaces to know what other problems that could cause.
Now that I have super power on the repository, I can apply my patch on it. I'll try to redo a clean pull request and see if anyone yells against it.
It's in the master on github.
(1-10/10)
Subject: Better support of Namespace for Model
Hi,
I found some problems with using namespace models.
This is the changes I made to resolve these problems.
I assume that models will always be in the same namespace.
(I'm using the 2011/02/28 nightly build)
--
Add this into ActiveRecord\Config :
Now, we can set namespace in configuration like that :
--
Update ActiveRecord\Reflections::get_class() :
--
Update ActiveRecord\AbstractRelationship::set_class_name() :
--
"has_many through" doesn't work with namespace, we must also update ActiveRecord\HasMany::load() :
--
Now, this code works fine :
This tweaks are made for resolving "has_many" issues. Sames issue may appears with "belongs_to", but i don't look at this yet.
(sorry for my bad English, this message was translated from french)