views:

68

answers:

1

Hey guys (and girls ^^) !!!

Does sommebody knows how to do a "join" with an anonymous scope in ruby ??? With a named scope you just have to add ":joins =>....." but i can't really find the way to do it with anonymous ones ... .

Thx in advance for the help ;)

A: 

It probably depends on the context of where you're trying to join. Within the context of the class of any model, scope(:find) will return the parameters of the current scope and these can be combined or re-interpreted into a join if required.

Can you amend your question with some example code?

tadman
An example : i've a class Company which has_one "information" (in the database => 2 tables, companies and informations)scope = Company.scoped({})scope = scope.conditions "informations.size >= ?", datas[:with_size_gt], unless datas[:with_size_gt].blank?With this, i've got a mysql error telling me that it can't find the column "informations" what is normal cause it's a different table.In the original named_scope, there is a :join => [:informations] which make it work but i donno how to do it in my anonymous scope ...I hope this is clear ^^
Mathieu
Sounds like you could use a relationship counter cache and avoid having to do a join in the first place. Then you can do a simple select on "companies.informations_count>=?" instead.
tadman