M
M
Meridian3122014-08-17 16:56:27
Ruby on Rails
Meridian312, 2014-08-17 16:56:27

How to properly share migration schema and model attributes in Rails?

You need to create multiple models, all of which have common attributes. How to make all definitions DRY.
For example
Model A, has attr_1 string, attr_2 int, attr_3 int
Model B and Model C include definitions for Model A's schema and its attributes
While neither model follows the STI pattern as sub-models can have their own unique attributes .

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vsuhachev, 2014-08-17
@vsuhachev

There are 2 options: inheritance and concerns (aka mixins). The main differences are in the meaning that you put into the relations of these classes.
If B is a subclass of A, then it makes more sense to use inheritance. Example - 'Car' and 'VAZ 2109'
If A and B are heterogeneous entities that have some common functionality, then it is more logical to use concerns. Example - 'Car' and 'Elevator' may have common functionality related to passenger loading.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question