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 ] )

3 comments :

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

ih1ux834sv said...

The dimension and complexity of the plastic elements are additionally necessary components suppose about|to contemplate}. If you want to make a small variety of merchandise, then have the ability to|you probably can} choose a simple design on your mold. However, if you want to|if you wish Hat to} make giant quantities of merchandise at once, then want to|you should|you have to} purchase an advanced-level mold with intricate designs. These kinds of molds are additionally costlier than simple ones end result of|as a result of} they require extra time and effort from the manufacturer. In order to reduce back} the time required to develop a product, it is not uncommon} for the product design and the mold design to be carried out on the same time.

66v4rbt3m5 said...

For example, [3D Systems’] Figure four Production totally automates the method from data prep to help cleaning, which is achieved through the combination of producing and robotics. Surrounding all this is the need Energel Liquid Gel Pens for standards for materials, processes, and software—work that is still in its infancy. Within this mix, the applications being pursued are so diverse that the needs are very different. For roughly 15 years, he was a member of the engineering staff charged with developing all the company’s 3D printing platforms. “As a staff, we enhanced the capabilities of these platforms and, within the course of, secured tons of of patents,” stated Kulkarni. Imagine, design, develop, and manufacture lengthy run} with 3D printing and additive manufacturing.