Forum: Ruby on Rails What is the best way to handle this? It's not a good use of

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Glenn S. (Guest)
on 2006-04-04 23:26
(Received via mailing list)
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
project to rewrite in rails, if not for this customer then perhaps for

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

    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)
    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)

    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
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
rails about the links manually?  ie.  (and I've not sure this code is
but you get the idea)

class Request < ActiveRecord::Base
    has_one   :created_by,
                   :class_name => "User",
                   :foreign_key => "created_by_id"

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


Adam B. (Guest)
on 2006-04-05 09:09
I'm not sure about the code either, but yes, Rails needs to be told (in
that manner) about the links.

Hope that helps,

This topic is locked and can not be replied to.