On Tuesday, June 12, 2012 9:55:43 AM UTC-7, Sean Redmond wrote:
>
> Hi,
>
> Let's say I'm joining three tables like so (this is a many-to-many
> relationship between TableA and TableC, where TableB is the join table):
>
> TableA.join(TableB, :a_id => :a_id).join(TableC, :c_id =>
> :c_id).filter(:table_c__field1 => 1, :table_c__field2 => 1,
> :table_b__field3 => 1)
>
> This works perfectly well to select all the fields from all the tables
> ("SELECT * FROM ...), but how do select just the fields from TableA
> ("SELECT table_a.* FROM...)
>
Add .select_all(:table_a) to the end of that method chain.
>
> The obvious follow up: can this be done just with associations? I have the
> many_to_one set up in my TableA model so that it can, for instance,
> retrieve all the associated records from TableB and TableC, but I'm not
> sure how it would work just to filter TableA. The twist is that the fields
> it needs to be filtered on exist in al the table which is why they have to
> be spelled out (":table_c__field1 => 1") in the statement above.
>
>
You'll have to provide more details/code before I can answer that.
Thanks,
Jeremy
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/sequel-talk/-/xtYmupV51e8J.
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/sequel-talk?hl=en.