Forum: Ruby on Rails Foreign Keys

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Alana (Guest)
on 2006-04-11 14:53
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
Richard W. (Guest)
on 2006-04-11 17:14
(Received via mailing list)
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.
This topic is locked and can not be replied to.