Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Foo < ActiveRecord::Base
- has_one :bar, ->(current_user) { where(user_id:current_user) }
- end
- class Bar < ActiveRecord::Base
- belongs_to :foo
- belongs_to :user
- end
- class User < ActiveRecord::Base
- has_one :bar
- end
- > Foo.first.bar(2)
- SQL => Foo Load (1.2ms) SELECT "foos".* FROM "foos" ORDER BY "foos"."id" ASC LIMIT 1
- Bar Load (0.7ms) SELECT "bars".* FROM "bars" WHERE "bars"."foo_id" = ?
- AND "bars"."user_id" = 1 LIMIT 1 [["foo_id", 1]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement