Hi, IÂ?m doing a project for a company (my first big project in rails).
The company alredy has a database schema, with lots of data, so I donÂ?t
want to change the database schema, but I donÂ?t know how to map some
associations.
Example:
Table: application
Primary Key: idapplication
Table: module
Primary Key: idmodule
Foreign Key: idapplication References aplicattion: idapplication
Table: category
Primary Key: idcategory
Foreign Key: idapplication References application: idapplication
Foreign Key: idmodule References module: idmodule
An application has manies modules and a module has manies categories.
Ok, I guess thatÂ?s the easy one, the first caseÂ?
Then I have another cases, in example
Table hours:
Primary key: id
Foreign key: idpar Refeernces: hours :id
An hour tuple has a relation with another hour tuple by the idpar key,
so in example
Hour id: 1 idpar: 2
Hour id: 2 idpar: 1
Another case:
Table user
Primay key: iduser
Table work:
Primary key: idwork
Foreign key: iduser references user: iduser
Foreign key: idcreator references user: iduser
So, a work has a user assigned, a user who is a creator and a user who
is an it person
Another case:
Table user:
Primary key: iduser
Table work:
Primary key: idwork
Table user_work:
Foreign key iduser references user: iduser
Foreign key idwork references work: idwork
So, a user is related to many works and a work is related to many users,
no primary key in table user_work, so I donÂ?t know what to do there
And the last one:
Table status_sir
Primary key: idstatussir
Table status_sir_next
Foreign key: idstatussir references status_sir: idstatussir
Foreign key: idstatussir_next references status_sir: idstatussir
No primary key in the table status_sir_next, so I donÂ?t know what to do,
the idea is that if you are in state 2, then you will have two tuples in
status_sir_next:
Idstatussir: 2 Idstatussir_sig: 3
Idstatussir: 2 Idstatussir_sig: 4
So now you know that if you are in state 2 you can go to state 3 or 4
Well, thatÂ?s all, I already did something, in example:
class Aplicacion < ActiveRecord::Base
#Setear el nombre de la tabla y la primary key
set_table_name “aplicaciones”
set_primary_key “idaplicacion”
end
Sorry for the spanish, btw, I know how to set the table name and the
primary key, but I get lost when a table has not a primary key. Besides,
I donÂ?t know how to specify the relations with belong_to and has_many in
these tables, I readed some things about the :class_name, :foreign_key
and :conditions hash options but I just donÂ?t know how to use them in
those cases.
Thank you for your time
Rodrigo DomÃnguez
Consultor
Av. Directorio 183 1º Piso
Tel: 4921-1648 / 4926-1067
Cel: 15-5695-6027
mailto:[email protected] [email protected]
http://www.rorra.com.ar/ www.rorra.com.ar