D
D
Daniel2542015-01-23 20:27:19
Ruby on Rails
Daniel254, 2015-01-23 20:27:19

How in Rails, when creating one model, take data from other models?

Hello!
I want to create a table where the data of automobile tires would be stored. Tires have parameters such as name, load index and speed index. The indexes themselves and their corresponding values ​​are stored in two other tables.
There are three models.

Tire: (belongs_to :load_index; belongs_to :speed_index)
  name:string
  speed_index:references
  load_index:references
LoadIndex: (has_many :tires)
  index:integer (Тут индекс нагрузки)
  value:integer (Тут значение нагрузки, соответствующее индексу нагрузки)
SpeedIndex: (has_many :tires)
  index:string (Тут индекс скорости)
  value:integer (Тут значение скорости, соответствующее индексу скорости)

Is there some easy way to create a Tire instance knowing only the index value from load_indices and speed_indices and not knowing the corresponding speed_index_id and load_index_id?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Vsk, 2015-01-23
@viktorvsk

There is.
And if you need something else, arrange the question in code blocks and describe the task normally (for example, in more detail)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question