Modelling Ruby on Rails

Asked

Viewed 104 times

0

Guys I have a question I can’t see what the way to solve.

I have to perform a stock program in Ruby on Rails that contain some equipment, which will contain some avergiguações.

For example, I will have computers, printers, telephones, among others, each with its own table, because it contains unique elements each one.

Then I would need to create a 1-to-N ratio in Ruby on Rails, because a computer can have N inquiries, but a printer can also contain N inquiries, the phone, and all other equipment.

So the question is, do I have to reference all the tables in the survey creation, but only fill in the one I would use? for example:

Rails g scaffold Inquiry Description:string date:date computer:Ference printer:Ference phone:Ference

I don’t think it’s like that but I can’t figure out what the right way would be.

2 answers

0

I think it’s in logic that Alex said. Each piece of equipment has several checks, while several checks belong to one piece of equipment. This is a one-to-many relation (one_to_many).

Then more or less it would be

Rails g scaffold Equipment name:string description:string

And then

Rails g scaffold Inquiry inquiry:text equipment:references

Once done, after the db:migrate Rails, just specify the relationship between these two models.

No model Equipment has_many :inquiries

No model Inquiry belongs_to :Quipment

Probably some adjustments should be made in Views, since in Equipments it will be possible to see, and edit the inquiries. If you are running multiple tests, remember that it is possible to undo changes just by changing the "g" from generate to "d" from Destroy.

Ex: rails d scaffold Equipment

I know this seems simple, but this can avoid a lot of problems. Especially when we are just testing.

0

I would not create a table for each type of equipment, but a table of equipment.

In this case, equipment has N inquiries normally.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.