On Feb 20, 4:58 am, Simon Arnaud <[email protected]> wrote:
> Thanks for your reply, it works great.
>
> Now, let's get a bit more involved. Those shoes are created in a
> country.
> So we have a country table.
>
> Now I would like to do things like :
> 1) Shoe.from_france
> 2) Person.with_shoes_from_france
> 3) Person.with_red_shoes.from_france
>
> The first one is easy, I'm just wondering if the :graph_join_type is
> also :inner, or if it should :outer, :natural, or whatever. I'm not an
> expert in SQL, moreso in the different types of JOINs.

1) is easy, basically the same idea as discussed before

> The second one seems tricky, and surely can't be done with only a
> one_to_many, or many_to_one. It looks like a many_to_many, and using a
> mix of the :graph_* and :eager_* methods. I looked at the
> has_many :through example, but I can't figure out how to apply it on
> this example.

2) isn't hard, you just use eager_graph(:shoes=>:countries) or
whatever to cacade, and set your filters appropriately.

> The third one looks like it should work, but since the first method
> returns a Dataset, and not a Shoe,  it does not. And I don't see how
> it could be handled.

3) won't work, at least not without a separate dataset method on
Person named from_france (which wouldn't really make sense).

> Now, I'm wondering if I'm taking the good approach on this. I'm not
> interested in the associated objects, I just want to filter the Person
> based on associated objects, and it seems quite complicated, when it's
> quite simple in SQL.

If you don't care about the associated objects, joining manually is
probably the best way to go.

> Is there any simpler way to tackle this ?
> Something that would look like :
> Person.filter( :shoes => { :color => 'red' }).filter( :shoes =>
> { :country => { :name => 'france' } } )

Person.select(:people.*).join
(:shoes, :id=>:shoe_id, :color=>'red').join
(:country, :id=>:country_id, :name=>'france')

Jeremy
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sequel-talk" 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/sequel-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to