Foreign Keys


#1

Hi,

My tables are as follows:
“tblusers” - primary key “TblUsersID”
“tblregisteredphones” - primary key “TblRegisteredPhonesID”
- foreign key “intUserID”

My models are as follows:

class Registeredphone < ActiveRecord::Base
set_table_name “tblregisteredphones”
belongs_to :user,
:foreign_key => “intUserID”
set_primary_key(:TblRegisteredPhonesID)
end

class User < ActiveRecord::Base
set_table_name “tblusers”
has_many :registeredphones,
:foreign_key => “TblUsersID”
set_primary_key(:TblUsersID)
end

Is this correct?

Thanks,
Alana


#2

On Tuesday, April 11, 2006, at 12:53 PM, Alana wrote:

set_table_name “tblregisteredphones”
end
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails

Looks correct. If you are never going to use the relation from
registeredphones to users you do not need the “has_many” on the
registeredphones model.