find_by_parent_id

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?

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?

Thanks