Monday, July 21, 2014

Using activerecord to find associated models

Let say I have two Model like below

class Plan < ActiveRecord::Base
    has_many :clients

end

class Client < ActiveRecord::Base
    belongs_to :plan

end

 For example I wanted to find all clients which has a plan_id = 5, here is the code
clients = Client.all( :include => :plan, :conditions => [ 'plan_id=?', 5 ] )

1 comment :

Anonymous said...

The King Casino: Get a $500 Bonus - Jancasino.com
The King Casino was designed to 더킹카지노 cater to every player. It is an exciting destination for players with the ミスティーノ possibility to choose a game from any