Hi All,
Thought I'd close this off with how I did it...
It was actually much easier than I'd expected.  Simply created another 
model with has_many relationships to the models I need to mash.  It was 
then easy to pull that collection and grab from both models in the orders I 
needed.  The model is basically an index of 2 different models, and maybe I 
could have used indexing, but it allowed me to build a tailored collection 
of mashed cards with easy querying.  Also used this model to build totals 
for querying and quick looks ups of categories they belonged to (not ideal, 
as it kinda duplicates).

Regards, Anthony.

On Wednesday, January 16, 2013 11:59:02 AM UTC, Bryan Larsen wrote:
>
> 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] <javascript:>> 
> 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]<javascript:>. 
>
> > To unsubscribe from this group, send email to 
> > [email protected] <javascript:>. 
> > 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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/hobousers?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to