On Thursday, September 19, 2013 10:20:27 AM UTC-7, Jarrod Manzer wrote:
>
>
> My bad, I did not completely scrub the example of my original table/column
> names. Your example definitely helped as I came up with this working query.
> Also I did not know about the ___ notation as I had not noticed it in the
> docs before. The use of %w is definitely cleaner here as well.
>
> irb(main):086:0> ap
> DB[:albums___a].left_join(:albumsstags___at,:albumid=>:id).left_join(:tags___t,:id=>:tagid).where(:country=>%w'us
>
> uk',:style=>%w'rap country',:name=>%w[red blue]).select(:title).sql
>
> "SELECT `title` FROM `albums` AS `a` LEFT JOIN `albumsstags` AS `at` ON
> (`at`.`albumid` = `a`.`id`) LEFT JOIN `tags` AS `t` ON (`t`.`id` =
> `at`.`tagid`) WHERE ((`country` IN ('us', 'uk')) AND (`style` IN ('rap',
> 'country')) AND (`name` IN ('red', 'blue')))"
>
> Thank you, I learned much about sequel in getting through this:)
>
> As another question, should this be done with models and if so what would
> that look like?
>
Probably not, but if you do want to do so:
Albums.many_to_many :tags, :join_table=>:albumsstags, :left_key=>:album_id,
:right_key=:tagid
Albums.eager_graph(:tags).ungraphed.select(:title).where(:country=>%w'us
uk',:style=>%w'rap country',:name=>%w[red blue])
The only thing models would save you here is the the join criteria.
Also, If you just want an array of titles, you probably should use
.select_map(:title).
Thanks,
Jeremy
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" 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/sequel-talk.
For more options, visit https://groups.google.com/groups/opt_out.