Guest User

Untitled

a guest
Jul 19th, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. named_scope :current_selection, :conditions => ['ipayment_confirmed = ? and confirmed = ?', false, false]
  2.  
  3. # now this works:
  4.  
  5. User.first.checkouts.current_selection
  6. +----+----------+-----------+-------------------+-------------------+------------------+----------+-----------------+---------+-------------------+-------------------+
  7. | id | checksum | confirmed | ipayment_id | ipayment_confi... | date_of_purchase | discount | discount_amount | user_id | created_at | updated_at |
  8. +----+----------+-----------+-------------------+-------------------+------------------+----------+-----------------+---------+-------------------+-------------------+
  9. | 1 | 111111 | false | ac170c22UD5QnM... | false | 2009-12-07 | false | 0.0 | 1 | Mon Dec 07 18:... | Mon Dec 07 23:... |
  10. +----+----------+-----------+-------------------+-------------------+------------------+----------+-----------------+---------+-------------------+-------------------+
  11. 1 row in set
  12.  
  13. # but how do use this named_scope in a wrapper method so that i only get the first object back?
  14. # i tried it like this:
  15.  
  16. def current_selection
  17. scope = self.scoped :conditions => ['ipayment_confirmed = ? and confirmed = ?', false, false]
  18. scope.first
  19. end
  20.  
  21. # but this doesnt work:
  22.  
  23. >> User.first.checkouts.current_selection
  24. NoMethodError: undefined method `current_selection' for #<Class:0xb6a85bf4>
Add Comment
Please, Sign In to add comment