# What is the best way to handle this? It's not a good use of

**URL:** <https://www.ruby-forum.com/t/what-is-the-best-way-to-handle-this-its-not-a-good-use-of/56843>\
**Category:** Rails\
**Created:** [April 4, 2006, 9:26pm UTC](https://www.ruby-forum.com/t/what-is-the-best-way-to-handle-this-its-not-a-good-use-of/56843 "2006-04-04T21:26:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Glenn\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/bbce88/32.png) [@Glenn\_S](https://www.ruby-forum.com/u/Glenn_S)\
**Post date:** [April 4, 2006, 9:26pm UTC](https://www.ruby-forum.com/t/what-is-the-best-way-to-handle-this-its-not-a-good-use-of/56843/1 "2006-04-04T21:26:18Z")

</div>

Just getting back into Rails, so apologies.

Just a bit of advice please.

I’m trying to rewrite the change control app that I wrote originally in  
VB/Oracle. It’s used heavily by our project and customer and seems a  
good  
project to rewrite in rails, if not for this customer then perhaps for  
another.

Anyway, I have decided to go with MySQL this time and have the following  
(showing just the fields I’m really interested in here):

CREATE TABLE requests  
(  
id int not null auto\_increment,  
created\_by\_id int not null,  
last\_updated\_by\_id int,  
primary\_customer\_id int,  
primary\_support\_id int,  
:  
:  
constraint fk\_requests\_creator foreign key (created\_by\_id)  
references  
users(id),  
constraint fk\_requests\_updater foreign key (last\_updated\_by\_id)  
references users(id),  
constraint fk\_requests\_customer foreign key (primary\_customer\_id)  
references users(id),  
constraint fk\_requests\_support foreign key (primary\_support\_id)  
references users(id),  
primary key (id)  
);

CREATE TABLE users  
(  
id int not null auto\_increment,  
fullname varchar(100) not null,  
:  
primary key (id)  
);

Basically, the users table contains a list of everybody who uses the  
system. They can be customer and/or support people.

A request can be created by one user, then updated by another. So the  
created\_by\_id would contain the id of one user record, and perhaps an id  
of  
another (or perhaps the same) user record.  
The primary\_customer\_id and primary\_support\_id are similarly linked to a  
user record. And this created\_by\_id and last\_updated\_by will feature in  
other tables, such as tasks, attachments etc.

I _assume_ the only way to link these tables by these fields is by  
telling  
rails about the links manually? ie. (and I’ve not sure this code is  
right,  
but you get the idea)

class Request \< ActiveRecord::Base  
has\_one :created\_by,  
:class\_name =\> “User”,  
:foreign\_key =\> “created\_by\_id”  
etc…

Is this the best way to do this kind of thing, or is there a  
better/preferred way to handle this kind of thing?

Thanks

Glenn

---

<div class="post-metadata">

**Author:** ![Glenn\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/bbce88/32.png) [@Glenn\_S](https://www.ruby-forum.com/u/Glenn_S)\
**Post date:** [April 5, 2006, 7:09am UTC](https://www.ruby-forum.com/t/what-is-the-best-way-to-handle-this-its-not-a-good-use-of/56843/2 "2006-04-05T07:09:04Z")

</div>

I’m not sure about the code either, but yes, Rails needs to be told (in  
that manner) about the links.

Hope that helps,

Adam
