Displaying 2 results from an estimated 2 matches for "user_vote".
Did you mean:
user_votes
2009 Nov 09
3
How can I improve a Ruby on Rails code that hast a lot of SQL as strings?
...chance at all of using the ORM and less string?
- Any other thing to do to it?
The code is this one
class Item < ActiveRecord::Base
has_many :votes, :as => :voteable
def self.ranking(user_id)
Item.find(:all,
# items.* for all the Item attributes, score being the sum of votes,
user_vote is the vote of user_id (0 if no vote) and voter_id is just user_id
for latter reference.
:select => "items.*,
IFNULL(sum(all_votes.value), 0) as score,
user_votes.value as user_vote,
\"#{user_id}\" as voter_id",...
2006 May 13
4
undesireable lazy loading
Hi,
My work with Rails has been fairly straightforward, until yesterday...
I''ve encountered rather a peculiar problem that I''m not able to solve
myself as a rails-newbie.
The model code looks like this:
class Link < ActiveRecord::Base
has_one :user_vote
end
class UserVote < ActiveRecord::Base
belongs_to :user
belongs_to :link
end
I have a SQL query that is responsible for pulling out all links along
with votes from a database:
links = Link.find_by_sql(
["SELECT * FROM links LEFT JOIN user_votes ON links.id =
user_votes.link_id&q...