For slighly more idiomatic Ruby, you could use the attribute name
"active"
rather than "is active". The resulting query would then look
something
like:
Province.joins(:cities).where(:active => true).where("cities.active =
?",
true)
On Sat, Mar 19, 2011 at 9:49 AM, Frederick Cheung <
frederick.cheung-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
>
> On Mar 19, 7:11 am, Quee WM
<li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:
> > I have the following
> >
> > class Province < ActiveRecord::Base
> > has_many :cities
> > attr_accessible :name, :is_active
> > end
> >
> > class City < ActiveRecord::Base
> > belongs_to :province
> > attr_accessible :name, :province_id, :is_active
> > end
> >
> > now I want to get all the provinces with is_active = true which have
> > cities with is_active = true
> >
>
> You should be able to do this using the joins option to find (or in
> rails 3 by calling .joins(...)) to join the cities table to the
> provinces one. You''ll then be able to write conditions that refer
to
> both tables
>
> Fred
> > please guide me on how this can be done.
> >
> > --
> > Posted viahttp://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To unsubscribe from this group, send email to
>
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.