Created
December 10, 2008 22:24
-
-
Save myobie/34512 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Book | |
belongs_to :group | |
has n, :subscriptions | |
has n, :subscribers, :through => :subscriptions, :class_name => 'User', | |
:child_key => [:book_id], :remote_name => :user | |
end | |
class Group | |
has n, :books | |
has n, :users, :through => Resource | |
end | |
class User | |
has n, :groups, :through => Resource | |
has n, :books | |
end | |
class Subscription | |
belongs_to :book | |
belongs_to :user | |
end | |
Book.all 'group.users.user_id' => 1 # => SQL Error | |
# SELECT ... FROM `books` INNER JOIN `groups` ON (`groups`.`id` = `books`.`group_id`) | |
# INNER JOIN `groups` ON (`groups`.`id` = `groups_users`.`group_id`) | |
# WHERE (`groups_users`.`user_id` = 1) ORDER BY `books`.`id` | |
# it should look like: | |
# SELECT ... FROM `books` INNER JOIN `groups` ON (`groups`.`id` = `books`.`group_id`) | |
# INNER JOIN `groups_users` ON (`groups`.`id` = `groups_users`.`group_id`) | |
# WHERE (`groups_users`.`user_id` = 1) ORDER BY `books`.`id` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment