Created
October 3, 2011 06:23
-
-
Save d11wtq/1258550 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Message | |
include DataMapper::Resource | |
property :id, Serial | |
property :deleted, Boolean | |
belongs_to :sender, | |
'User' | |
belongs_to :recipient, | |
'User' | |
class << self | |
def visible | |
all(:deleted => false) | |
end | |
end | |
end | |
class User | |
include DataMapper::Resource | |
property :id, Serial | |
def messages | |
Message.all(:sender => self) | Message.all(:recipient => self) | |
end | |
end | |
# this works (returns records from the current query that have :deleted => false) | |
user = User.get(1) | |
user.messages.all(:deleted => false).count | |
# this doesn't (returns *all* records with :deleted => false... not scoped to the current query) | |
user.messages.visible.count |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment