Forum: Rails Germany Frage zu Sub-Select

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
90103cb825e0aa8fb7d7b6657f761fc7?d=identicon&s=25 Guido Pesch (Guest)
on 2008-10-10 15:21
(Received via mailing list)
Hallo zusammen,

wie baue ich diese SQL-Abfrage in Rails?

Select * from USERS WHERE id NOT IN (SELECT user_id FROM PLAYERS)

Es besteht eine 1 zu 1 Beziehung zwischen User und Player.

class User
has_one :player

class Player
belongs_to :user

Danke und Gruß
Guido
Bce1d1b7c3ec7b577dcb42e254899e6b?d=identicon&s=25 Michael Schuerig (Guest)
on 2008-10-10 16:38
(Received via mailing list)
On Friday 10 October 2008, Guido Pesch wrote:
> Hallo zusammen,
>
> wie baue ich diese SQL-Abfrage in Rails?
>
> Select * from USERS WHERE id NOT IN (SELECT user_id FROM PLAYERS)
>
> Es besteht eine 1 zu 1 Beziehung zwischen User und Player.
>
> class User
> has_one :player

User.find(:all, :include => :player,
  :conditions => "players.user_id IS NULL")

Michael

--
Michael Schuerig
mailto:michael@schuerig.de
http://www.schuerig.de/michael/
90103cb825e0aa8fb7d7b6657f761fc7?d=identicon&s=25 Guido Pesch (Guest)
on 2008-10-11 12:55
(Received via mailing list)
Vielen Dank Michael

Guido

Zitat von Michael Schuerig <michael@schuerig.de>:
This topic is locked and can not be replied to.