RockPaperScissors

LizardSpock

Activerecord Find All/Multiple

| Comments

Using Tags (An active record model) to find tags by the tag property:

Tag.find_by_tag("Ruby")
Ruby

Tag.find_by_tag(["Ruby", "Gem"])
Ruby

That did not return what I expected, find returns one object by default. first last or all modifiers can be used. So to find multiple tags by the same property:

Tag.find_all_by_tag(["Ruby", "Gem"]) 
Ruby
Gem

Again with slightly less active record magic:
Note the = ? for singular items and IN (?) for a list of items.

Tag.find(:all, :conditions => ["tag = ?", "Ruby"])
Ruby

Tag.find(:all, :conditions => ["tag IN (?)", ["Ruby", "Gem"]])
Ruby
Gem

More info can be read on Rails Guides.

Comments