rails belongs_to sql statement using NULL id
- by Team Pannous
When paginating through our Phrase table it takes very long to return the results.
In the sql logs we see many sql requests which don't make sense to us:
Phrase Load (7.4ms) SELECT "phrases".* FROM "phrases" WHERE "phrases"."id" IS NULL LIMIT 1
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" IS NULL LIMIT 1
These add up significantly. Is there a way to prevent querying against null ids?
This is the underlying model:
class Phrase < ActiveRecord::Base
belongs_to :user
belongs_to :response, :class_name => "Phrase", :foreign_key => "next_id"
end