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

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.
5246b4313d8a2dfabea5dd6db1d22df8?d=identicon&s=25 Glenn Smith (Guest)
on 2006-04-04 21: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
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
6ec1e89eef5ce09fbfa56be5b6dd17b5?d=identicon&s=25 Adam Bloom (admanb)
on 2006-04-05 07: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,

Adam
This topic is locked and can not be replied to.