Hi all, I have a has_many through relation and have written a scope for that. I don''t get the joins to work so I wrote the sql for the joins: scope :has_country_variation_for_country, lambda{|country_id| joins(''INNER JOIN variations ON variation_images.variation_id IS variations.id INNER JOIN country_variations ON country_variations.variation_id variations.id'').where(:country_variations => {:country_id => country_id})} This results in the following sql: SELECT "variation_images".* FROM "variation_images" INNER JOIN variations ON variation_images.variation_id IS variations.id INNER JOIN country_variations ON country_variations.variation_id variations.id WHERE ("country_variations"."country_id" = 1) It works perfectly in SQlite Manager and Base but not in rails or the sqlite3 console!!! I get "SQLite3::SQLException: near "variations": syntax error: " What have i done wrong? I use sqlite3 (1.3.3) This is the model: class VariationImage < ActiveRecord::Base has_many :country_variations, :through => :variation Thanks jonas -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.