Foreign key - relations

Hello,

I’ve got DB like this:

(roughly)
create table projects (
id int auto blabla,
name varchar(200),
user_id int,
sales_id int);

create table users (
id int auto…,
name varchar(50));

So project.user_id has a foreign key to user.id - all is good.
Everything works fine.

Now my question…
How can set a relationship from two different fields to the users table
??
Fx. I will user_is who might be the owner of the project, afterwards I
would like to assign a salesrep to the project… so sales_id should also
be looked up in the users table…

How do I tell rails about this relation ?

TIA,

/mich

class project < ActiveRecord::Base
belongs_to :users
belongs_to :sales,
:class_name => :User,
:foreign_key => :sales_id
end

should work.

Saludos!
HoraPe

On Fri, Jun 23, 2006 at 03:49:50PM +0200, mich wrote:

??

Posted via http://www.ruby-forum.com/.


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


HoraPe

Horacio J.
Peñ[email protected]
[email protected]

Horacio =?iso-8859-1?Q?J=2E_Pe=F1a?= wrote:

class project < ActiveRecord::Base
belongs_to :users
belongs_to :sales,
:class_name => :User,
:foreign_key => :sales_id
end

should work.

Thanks, that did the trick !