Ruby on Rails Friday, July 31, 2015

On Jul 31, 2015, at 11:43 AM, Nilay Singh <lists@ruby-forum.com> wrote:
>
> SO here is the code which I have tried in active record style :

I'm pretty sure this is different than what you posted last time.

And you might try giving a real answer to Elizabeth's question--that looks suspiciously like a bad schema design.

Anyway the answer to your immediate question is obviously in the join. You have this extremely strange join condition between the 2 tables, which you specify in that oddball case statement in the where clause. But you also have some has_many/belongs_to declarations in you model classes, and so when you try to use AREL, it adds what it believes to be the correct inner join clause, which restricts to... Well, just read the generated query and pay attention to the inner join clause to see what it's doing ;-)

Answer 1 is: fix your schema. Answer 2 is: if you cannot do that, then stick with find_by_sql because AREL's join method is never going to be able to cope with that structure.

--
Scott Ribe
scott_ribe@elevated-dev.com
http://www.elevated-dev.com/
https://www.linkedin.com/in/scottribe/
(303) 722-0567 voice





--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/266E6EC8-8B89-4823-A41F-CBA97E43342C%40elevated-dev.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment