Hi,
Searching with SQL is a good solution to make complex queries. Take into
account that with Rails 3 you can make a lot of queries without too much
SQL. For example:
Client.joins(:invoices => :invoice_lines).
group("clients.id").
having("sum(invoice_lines.price) > ?", 3000).
where("strftime('%Y', invoices.invoice_date) = ?", "2012")
}
Apart from this style thing, it is hard for me to imagine a case where
you need to mix two models in the same list. Maybe you could rethink
your view in a simpler way?
If you want to filter with fields from a related table, you can try the
Ransack gem. There's a Hobo gem that might help too:
https://github.com/suyccom/hobo-metasearch
Regards,
Ignacio
El 15/01/13 21:38, [email protected] escribió:
Hi Anthony,
I'm also pretty new to Rails/Hobo, but you may want to check out
find_by_sql. Given that you'll be losing database portability by
hard-coding the SQL, it's a last resort, but will let you do what you want.
Category.find_by_sql ("select ... from categories, venues, events...sort
by ....", bindings)
Again, I'm new, but I think you'd put in your controller:
@json=Category.find_by_sql ("....")
Then make reference in your cards to the @json variable.
Hopefully this is a start until a more complete/better answer arrives
Best regards,
Art.
On Tuesday, January 15, 2013 3:37:04 AM UTC-6, tonym 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/-/JF5A8iFx4fEJ.
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.
--
Ignacio Huerta Arteche
http://www.ihuerta.net
Teléfono: 0034 645 70 77 35
Email realizado con software libre
--
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.