Rails one to one association

I have an issue related to rails.
The class definition is given below.

class Supplier < ActiveRecord::Base
  has_one :criteria
  self.primary_key = 'sup_id'
end

class Criteria < ActiveRecord::Base
  belongs_to :supplier, :foreign_key => "crt_sup_id"
  self.primary_key = 'crt_id'
  self.table_name = 'criterias'
end

If I am using self.supplier in class Criteria it is working fine

but If I am using self.criteria in class Supplier then error thrown as,

Unknown column ‘criteria.supplier_id’ in ‘where clause’: SELECT
criteria.* FROM criteria WHERE criteria.supplier_id

I don’t have a field named supplier_id in criteria instead I am using
crt_sup_id as defined in the class.

Please help on this.

Thanks.

On 24 April 2013 10:39, ejo [email protected] wrote:

I have an issue related to rails.
The class definition is given below.

class Supplier < ActiveRecord::Base
  has_one :criteria

You need to specify the foreign key also (crt_sup_id) here as it is
non-standard.
On a side note I strongly recommend using the default id names unless
you absolutely cannot do that. It will make life much easier, as you
have already found.

Colin