rails belongs_to sql statement using NULL id

Posted by Team Pannous on Stack Overflow See other posts from Stack Overflow or by Team Pannous
Published on 2012-07-05T09:13:04Z Indexed on 2012/07/05 9:15 UTC
Read the original article Hit count: 180

Filed under:
|
|
|

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

© Stack Overflow or respective owner

Related posts about sql

Related posts about ruby-on-rails