Guest User

Untitled

a guest
Jun 13th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. # Gets count of ratings for all rated photos
  2. many_to_one :rated_photos_ratings_count, :class => Photo, :read_only => true do |ds|
  3. ds.join(:photo_ratings, :photo_id => :id).select{|o| o.count(:photo_ratings.*).as(:count)}
  4. end
  5.  
  6. # Geter for ratings count, needed because association returns array with one Photo object with count attribute
  7. def rated_photos_ratings_count
  8. (s = super) ? s[:count] : 0
  9. end
  10.  
  11. > u = User[4]
  12. ~ SELECT * FROM "users" WHERE "id" = 4 LIMIT 1
  13. ~ SET standard_conforming_strings = ON
  14. ~ SET client_min_messages = 'WARNING'
  15. ~ SET DateStyle = 'ISO'
  16. => #<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}>
  17. >> u.rated_photos_ratings_count
  18. NoMethodError: undefined method `rated_photos_ratings_count_id' for #<User:0x295f8b0>
  19. from /Volumes/Data/Users/Pavel/Sites/mujy/gems/gems/sequel-2.11.0/lib/sequel_model/record.rb:402:in `send'
  20. from /Volumes/Data/Users/Pavel/Sites/mujy/gems/gems/sequel-2.11.0/lib/sequel_model/record.rb:402:in `load_associated_objects'
  21. from /Volumes/Data/Users/Pavel/Sites/mujy/gems/gems/sequel-2.11.0/lib/sequel_model/associations.rb:307:in `rated_photos_ratings_count'
  22. from /Volumes/Data/Users/Pavel/Sites/mujy/app/models/user.rb:81:in `rated_photos_ratings_count'
  23. from (irb):2
  24. from :0
Add Comment
Please, Sign In to add comment