Created
November 18, 2010 02:04
-
-
Save ernie/704522 to your computer and use it in GitHub Desktop.
One of the reasons I love MetaWhere (I may be biased :))
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
# Can this be done with strings? Sure. This feels much nicer to me, though. | |
class Verb < ActiveRecord::Base | |
belongs_to :verbable, :polymorphic => true | |
belongs_to :objectifiable, :polymorphic => true | |
scope :of_interest_to_user, lambda {|u| | |
where( | |
(:objectifiable_type.eq % 'User' & :objectifiable_id.eq % u.id) | | |
(:objectifiable_type.eq % 'Book' & :objectifiable_id.in % u.book_ids) | |
) | |
} | |
end | |
# => SELECT `verbs`.* FROM `verbs` WHERE ( | |
# (`verbs`.`objectifiable_type` = 'User' AND `verbs`.`objectifiable_id` = 1 | |
# OR `verbs`.`objectifiable_type` = 'Book' AND `verbs`.`objectifiable_id` IN (1, 2, 3, 4)) | |
# ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment