Glenn Smith
2006-Apr-04 19:24 UTC
[Rails] What is the best way to handle this? It''s not a good use of the new Polymorphic-Association thingy is it?
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 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060404/04ca8239/attachment.html