Probably the easiest answer is to just do things in Ruby-land.   In
other words, treat the results of the query as arrays and use array
operations (like sort and +) on them.

@all = @foo.events + @foo.venues
@all.sort {|a,b|  a.created_at <=> b.created_at}

This is going to be slow if the arrays are big enough that you need
pagination.   But if large result sets are a rare occurrence, doing
things in ruby-land is sometimes your best option.

Bryan


On Tue, Jan 15, 2013 at 4:37 AM, tonym <[email protected]> wrote:
> Hi All,
>
> OK, this is something I'm about to tackle, but before I start I get a
> feeling I need help ;)
> Here's the scenario...
>
> I have 3 models.  'Category' has a many to many relationship with the two
> other models (venue and event).
> I need to create a single collection (output as cards) which lists all
> venues and events, but also, each venue or event will be listed for each
> category it is in (so can be listed more than once).
> i.e.
> Event 1 (Category 1)
> Venue 1 (Category 1)
> Venue 1 (Category 3)
> Venue 2 (Category 1)
> Venue 3 (Category 2)
> Event 2 (Category 1)
> Venue 3 (Category 3)
> Event 2 (Category 2)
>
> The whole list will be sorted and filtered on various fields such as date
> and local area that they are in (as well as category).
>
> Is it possible to 'include' all the events and venues in my Category
> controller, sort them and then output the whole thing as a collection?
>
> To be honest, not entirely sure on the best way to approach this, so any
> pointers would be very welcome.
>
> And just to complicate things! I also need to do an 'outer join' on the
> venue to event relationships - is there an hobo way to do an out join?
>
> Cheers, Anthony.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Hobo Users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/hobousers/-/UmArnKDSpeEJ.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/hobousers?hl=en.

-- 
You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/hobousers?hl=en.

Reply via email to