I guess it will return all the objects whose parent_id is assigned. But I
get only an object.
I have to do like these
@parent_id = params[:parent_id]
if @parent_id.nil?
conditions = ["parent_id is null"]
else
conditions = ["parent_id = ?", @parent_id]
end
@categories = Category.find(:all, :conditions => conditions)
But I expected that can be done like this
@categories = Category.find_by_parent_id(params[:parent_id]) # only
one object
Does anybody have good idea?
--
http://sourceforge.net/projects/mycodeline/
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
huang zhimin wrote:> I guess it will return all the objects whose parent_id is assigned. But > I get only an object. > > I have to do like these > > @parent_id = params[:parent_id] > if @parent_id.nil? > conditions = ["parent_id is null"] > else > conditions = ["parent_id = ?", @parent_id] > end > @categories = Category.find(:all, :conditions => conditions) > > But I expected that can be done like this > @categories = Category.find_by_parent_id(params[:parent_id]) # > only one object > > Does anybody have good idea?Perhaps you''re looking for find_all_by_parent_id? -- Cheers, - Jacob Atzen --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks On 6/20/07, Jacob Atzen <jacob-4U2y0bnePT5NzRJJ8cAMrg@public.gmane.org> wrote:> > > huang zhimin wrote: > > I guess it will return all the objects whose parent_id is assigned. But > > I get only an object. > > > > I have to do like these > > > > @parent_id = params[:parent_id] > > if @parent_id.nil? > > conditions = ["parent_id is null"] > > else > > conditions = ["parent_id = ?", @parent_id] > > end > > @categories = Category.find(:all, :conditions => conditions) > > > > But I expected that can be done like this > > @categories = Category.find_by_parent_id(params[:parent_id]) # > > only one object > > > > Does anybody have good idea? > > Perhaps you''re looking for find_all_by_parent_id? > > -- > Cheers, > - Jacob Atzen > > > >-- http://sourceforge.net/projects/mycodeline/ --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---