我想在客户端上编写一个 Rails 3 范围来执行以下操作:
select * from clients c, dependents d
where d.last_name like '%ss%' and c.id = d.client_id;
依赖模型:
class Dependent < ActiveRecord::Base
belongs_to :client
scope :by_last_name, (lambda do |name| { :conditions => ['last_name LIKE ?', "#{name}%"]} end )
客户型号:
class Client < ActiveRecord::Base
has_many :dependents, :dependent => :destroy
我还没有能够让范围连接在语法上工作。依赖的姓氏需要作为参数传入。谢谢。