Rails 4 chaining scope -
i reuse scope defined, returns array.
scope :currents, -> { (where('started_at < now()') | where('started_at' => nil)) & where('ended_at > now()') & where('published_at < now()') } def self.findnextauctions() currents.order(ended_at: :asc).limit(3) end
when call function findnextauctions error:
1) error: auctiontest#test_should_fint_next_auctions: nomethoderror: undefined method `order' #<array:0x007fae5d6e3878> app/models/auction.rb:13:in `findnextauctions' test/models/auction_test.rb:14:in `block in <class:auctiontest>'
rails doesn't have or statement. can write sql directly though like
where("(started_at < now() or started_at = null) , ended_at > now() , published_at < now()")
Comments
Post a Comment