Topic: get the records using eagerloading

Hi
i have 3 tables
1) gems
2)users
3)user_gems

In gems model

  has_many :user_gems, :foreign_key => 'gem_id', :class_name => 'UserGems'
   has_many :users, :through => :user_gems

 
in user model

  has_many :user_gems, :foreign_key => 'user_id', :class_name => 'UserGems'
   has_many :gems, :through => :user_gems

in UserGems model

belongs_to :gems
belongs_to :users

Now i want get all the gems from gems table except gem_id 's with user_id = 1 in users_gems table
for exmple
i have records  in join table

1 ) id = 1 gem_id = 2 user_id = 1
2) id = 2 gem_id = 3 user_id = 1
3) id = 3 gem_id = 4 user_id = 2

in my conditions user_id is 1
now i want to get the gems except 2 and 3


how to get this .can anybody help

Re: get the records using eagerloading

maybe this?

Gem.find(:all, 
  :conditions => [
    "id NOT IN (SELECT gem_id FROM user_gems WHERE user_id = ?)",
    current_user.id
  ]
)

Re: get the records using eagerloading

You can get a basic information and explanation about eager-loading and the difference with lazy-loading by the following url
http://rubyonrails4us.wordpress.com/201 … zyloading/