Displaying 2 results from an estimated 2 matches for "voteable_type".
2009 Nov 09
3
How can I improve a Ruby on Rails code that hast a lot of SQL as strings?
...# The first join gets all the votes for a single item (to be summed
latter).
# The second join gets the vote for a single user for a single item.
:joins => ["LEFT JOIN votes as all_votes ON
all_votes.voteable_id = items.id and
all_votes.voteable_type = \"Item\"",
"LEFT JOIN votes as user_votes ON
user_votes.voteable_id = items.id and
user_votes.user_id = \"#{user_id}\" and
user_votes.voteable_type = \"Item\""...
2007 Dec 20
3
ActiveRecords Eager Loading
...ke about 3 seconds to execute. (before indexing it is about 25
seconds)
SELECT DISTINCT articles.id
FROM articles LEFT OUTER JOIN assets ON assets.attachable_id =
articles.id AND assets.attachable_type = ''Article''
LEFT OUTER JOIN votes ON votes.voteable_id = articles.id AND
votes.voteable_type = ''Article''AND user_id = 2
WHERE (assets.parent_id is null)
ORDER BY stat_final_ranking desc
LIMIT 20
-----------------------------------
so, what I plan to do it is to cache the expensive query without
including vote table
Article.find(:all, :include => [:asset],...