我在rails 4 <转换rails 2 scope语法时遇到了问题
class Region <ActiveRecord :: Base
has_many:位置
结束
class Location <ActiveRecord :: Base
belongs_to:region scope :permitted, lambda {|p_id| {:joins => "left join person_locations pl on pl.location_id = locations.id", :conditions => ["pl.person_id = ? AND pl.active = 'Yes'", p_id]} }
#where pl = person_location
结束
class PersonLocation <ActiveRecord :: Base
belongs_to:location
结束
class LocationsController <ApplicationController
def index @locations = @region.locations.permitted(current_person.id).active.all(:order => "name")
respond_to do | format |
format.html #index.html.erb
结束
结束
结束
- List item
2 回答
我会写:
或者,如果可以将
person_locations
的关联添加到Location
模型中:也许
?