Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>It is possible.</strong></p> <p>You have to manually do something that :include does internally. It means integrating with AR internal API, which is not something you normally wish to do - it can break at any time when you're upgrading Rails. </p> <p>This means you should:</p> <ol> <li>instantiate Conversation objects manually from query result</li> <li>attach loaded Conversation objects to the association in Message objects</li> </ol> <p>Altough I suggest splitting into two queries, so that the you load Conversation objects through a second query - based on the conversation ids you get in the first query. It is better for performance in most cases. After that you just need attach loaded objects into association of Message objects.</p> <p>To give you a rough example of the logic:</p> <pre><code># complex query to load messages and conversation ids messages = Message.find(...) # parse the loaded conversation ids out of resulting Message objects con_ids = messages.map {...} # load conversation objects through 2nd query conversations = Conversations.find(con_ids) # group conversations by message id con_by_message = conversations.group_by(&amp;:message_id) # attach conversations into associations of Message objects messages.each {|m| m.conversations.target = con_by_message[m.id] || [] } </code></pre> <p>This is something that worked for has_many associations in Rails. I can't tell you if setting association.target is enough for habtm associations - you should digg up that in the source...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload