Can anyone explain to me the sql query done in the last step :
–
Arpit J.
It has nothing to do with polymorphism. You’ll want to look into eager
loading for your associations if you want to avoid those queries.
http://railscasts.com/episodes/22
-e
On Feb 27, 5:58 pm, Arpit J. [email protected] wrote:
Can anyone explain to me the sql query done in the last step :
Because activerecord isn’t super smart in this way and doesn’t fill in
associations bidirectionally when they are loaded.
Fred
So what’s the solution to that Fred ? I would have to load question also
when I load the subquestion ? That would mean doing a different query
twice
for extracting the same object. Or is there any other way around ?
On Sat, Feb 28, 2009 at 5:15 AM, Frederick C. <
On Feb 28, 1:57 am, Arpit J. [email protected] wrote:
So what’s the solution to that Fred ? I would have to load question also
when I load the subquestion ? That would mean doing a different query twice
for extracting the same object. Or is there any other way around ?
There isn’t really good solution. There’s a plugin that attempts to
address this (parental_control), or you can fiddle around making ar
believe it has already loaded it. The ar_context plugin can also be
helpful in this context.
You can also make your include load it (ie :include => {:subquestion
=> :question} but that always seems a bit messy.
You also do things semi manually ie instead of referencing
foo.question, collect all the questions into a hash indexed by id and
access your_hash[foo.question_id]
Fred
hmm Right… Thanks
On Sat, Feb 28, 2009 at 5:27 PM, Frederick C. <
[email protected]> wrote:
address this (parental_control), or you can fiddle around making ar
Fred
–
Arpit J.
–
Arpit J.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs