Donnerstag, 26. Juni 2008

named_scope

in the *.rb models

Class Profile << ActiveRecord::Base
belongs_to: user
belongs_to: team
named_scope :captain, :conditions => { :role => "captain" }
named_scope :liverpool, :include :team, :conditions => { 'teams.name' => 'liverpool' }
end

This allows following:

user.profile.liverpool #-> finds all user profiles that are in the team liverpool
user.profile.captain #-> finds all user profiles that have the role of captain.

Keine Kommentare: