On Apr 1, 1:01 am, Simon Arnaud <[email protected]> wrote:
> I was also wondering how to do this :
>
> I have the town code (not id), which is unique, for example "FR43286"
> I have this hierarchy for geos : town > department > region > country
> I want all the veterinary leaders (department, region, country), which
> might be 0, 1 or many.
>
> I tried
> Geo.filter(:code =>
> "FR43286").first.ancestors.leaders.type.filter(:name => "veterinary")
>
> but it does not work, and I would be very surprised if it would.
To do this in a single query, you'd need a recursive common table
expression. For multiple queries, maybe something like:
class Geo
def veterinary_leaders
cur = self
vls = []
while(cur) do
vls.concat(cur.leaders_dataset.
eager_graph(:type).
filter(:type__name=>"veterinary").all)
cur = cur.par
end
vls
end
end
> After some thinking, I was wondering if I can express an intersection
> with sequel to solve this problem. Something like :
> Leader.filter(:type => "veterinary).all.intersect(Geo.filter(:code =>
> "FR43286").first.leaders)
>
> Sounds possible ?
Not the way you are doing it. Dataset#all returns an array, and I
doubt you've defined Array#intersect.
It's possible to get something like this to work:
Leader.filter(:type => "veterinary).
intersect(Geo.first(:code =>"FR43286").
leaders_dataset)
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.