Exists? method for a table with no primary key


#1

Hi,
I am loving ruby on rails day by day… Today I wanted to use exists?
method for Activerecord.

My model is -
class PersonEngagement < ActiveRecord::Base
#this table does not have id as it is a legacy table
#Also it has no primary key
end

Attributes are person_id, engagement_id, etc

I want to check if a particular person <> engagement pair exists.

So I used PersonEngagement.exists? [‘person_id = ?’,person.person_id]
and I got -
ActiveRecord::StatementInvalid in ‘EngagementsHelper should check
whether the pe
rson works on an engagement’
Mysql::Error: Unknown column ‘person_engagements.id’ in ‘field list’:
SELECT pe rson_engagements.id FROM person_engagements WHERE (person_id = 123) A
ND (person_engagements.project_id = 1111) LIMIT 1

Should this be a patch to the original method ?
P.S.
Source of exists?
# File vendor/rails/activerecord/lib/active_record/base.rb, line
688
688: def exists?(id_or_conditions)
689: connection.select_all(
690: construct_finder_sql(
691: :select => “#{quoted_table_name}.#{primary_key}”,
692: :conditions => expand_id_conditions(id_or_conditions),
693: :limit => 1
694: ),
695: “#{name} Exists”
696: ).size > 0
697: end