Friday, May 14, 2010

[Rails] Combining multiple finds into one result

What I want to do is something like this:

searchid = 4
while searchid != -1
@a += A.find_by_someid(searchid)
@b = B.find_by_someid(searchid)
searchid = @b.parentid
end

The problem being the line

@a += A.find_by_someid(searchid)
The error being something like

NoMethodError: undefined method `+' for #<A:0x173f9a0>

I tried to simply do a @a=[] but then it complains 'A' cannot be
converted into an Array.

So, how do you combine multiple 'find' requests?
And what format do the finds return if not an array?
The output from a find looks something like:
=> #<A id: 99, name: "A Name">

Thanks
--
Posted via http://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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate