开发者

trying to walk a tree, always getting no results

I have a n-tier affiliate system which I'm trying to walk so I can get counts and lists of affiliates' sub-af开发者_StackOverflowfiliates. I have, among other fields, an "id" and "affiliate_id" on each entry.

def find_affiliates_under(affid)
  affs=Array.new
  Affiliate.find(:all, :conditions => "affiliate_id = " + affid.to_s, :select => :id).each do |a|
    affs.concat(find_affiliates_under(a.id))
  end
return affs.uniq
end

What am I doing wrong? Would appreciate a pointer from someone with more experience with Ruby Thanks!


Are you the id's or are you also looking for the nested objects themselves. By placing a select => :id option, you're only going to select the id of each object.

May I recommend taking a look at awesome_nested_set. I think it will achieve what you're trying to do, while saving you some time.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜