On May 2, 8:00 pm, GregD <[email protected]> wrote: > All, > > Need some help, please. many_through_many with conditions. > > simple. have 3 simple tables players, teams, teams_players. > > Player Model will have a many_through_many to get teammates. > > many_through_many :teammates, [[:teams_players, :player_id, :team_id], > [:teams, :id, :id], [:teams_players, :team_id, :player_id]], :class > => :Player > > This includes self. How do I exclude self? I don't want to do > self.teammates - [self]. This should be done in the sql with a > condition.
If you don't care about eager loading, it's easiest to just use a block: many_through_many :teammates, [[:teams_players, :player_id, :team_id], [:teams, :id, :id], [:teams_players, :team_id, :player_id]], :class => :Player do |ds| ds.exclude(:players__id=>id) end If you care about eager loading, you may have to use a custom eager loader or eager grapher. > I know this is will be simple, but finding it hard to find conditional > examples for sequel. > > For those that might be submitting documentation, some real good > examples of exclusion queries would be good: like: not in, not equal > to, left and right outer joins. All of which will be good beyond what > I call the 'hello world' examples. > > In my example, the current docs have 'Artist.many_through_many > artists' which is including self. It would have been nice to see the > conditional that would return all artists except self. I've added that to my todo list. 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.
