Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Gets count of ratings for all rated photos
- many_to_one :rated_photos_ratings_count, :class => Photo, :read_only => true do |ds|
- ds.join(:photo_ratings, :photo_id => :id).select{|o| o.count(:photo_ratings.*).as(:count)}
- end
- # Geter for ratings count, needed because association returns array with one Photo object with count attribute
- def rated_photos_ratings_count
- (s = super) ? s[:count] : 0
- end
- > u = User[4]
- ~ SELECT * FROM "users" WHERE "id" = 4 LIMIT 1
- ~ SET standard_conforming_strings = ON
- ~ SET client_min_messages = 'WARNING'
- ~ SET DateStyle = 'ISO'
- => #<User @values={:first_web_sign_in=>nil, :email_validated_at=>nil, :activated_at=>Mon Mar 23 17:22:25 +0000 2009, :guest=>false, :msisdn=>"447535630593", :location_id=>5, :last_action_at=>nil, :interested_in=>"M", :rating=>0, :birthday=>#<Date: 4909827/2,0,2299161>, :email=>"", :activation_code=>"572148", :language=>"en", :updated_at=>Mon Mar 23 17:51:13 +0000 2009, :salt=>"c63e0967f6db2bf09a778184db3f4a4f1c1b997f", :age=>0, :interested_in_age_from=>nil, :crypted_password=>"c8c5d36cd0f2d680ebfcde7221503f3d3c4dee13", :email_validation_code=>"4b1b31281705da6447b5a2fafd19a9ff1240565a", :interested_in_age_to=>nil, :nickname=>"natalie", :sex=>"F", :looking_for=>"friendship", :hot=>false, :blurb=>"", :id=>4, :created_at=>Mon Mar 23 17:22:09 +0000 2009}>
- >> u.rated_photos_ratings_count
- NoMethodError: undefined method `rated_photos_ratings_count_id' for #<User:0x295f8b0>
- from /Volumes/Data/Users/Pavel/Sites/mujy/gems/gems/sequel-2.11.0/lib/sequel_model/record.rb:402:in `send'
- from /Volumes/Data/Users/Pavel/Sites/mujy/gems/gems/sequel-2.11.0/lib/sequel_model/record.rb:402:in `load_associated_objects'
- from /Volumes/Data/Users/Pavel/Sites/mujy/gems/gems/sequel-2.11.0/lib/sequel_model/associations.rb:307:in `rated_photos_ratings_count'
- from /Volumes/Data/Users/Pavel/Sites/mujy/app/models/user.rb:81:in `rated_photos_ratings_count'
- from (irb):2
- from :0
Add Comment
Please, Sign In to add comment