Forum: Ruby on Rails exists? method for a table with no primary key

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
1ebcd34bbfe62169964bb9a5006de29f?d=identicon&s=25 Manasi V1 (manasi)
on 2009-05-20 12:25
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

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 '' in 'field list':
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 ?
Source of exists?
     # File vendor/rails/activerecord/lib/active_record/base.rb, line
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
This topic is locked and can not be replied to.