Relationship of products in models and bank

Asked

Viewed 112 times

0

I’ll try to be brief in my doubt.

How can I model a class scheme that gives me some questions: This I will do in Rails 4.1, using Activerecord as ORM acting in Mysql.

I’ll have an entity Person which will have a reference (object), to my model of Product, that is, none or many products, the case is that this will be the repository of the company, ie, all customers will have a unique registration that when logged in, check the products available to that user, which marries several products with different properties relating to a product.

For example :

Product A will have attributes:

  • color
  • size
  • heaviness

Product B will have attributes:

  • time remaining
  • numero_serie

The question is this how can I model this data abstraction?

I’ve been thinking, every new product we develop, we’d have to create a new class and add to that?

summing up again...

How to create an entity relationship where each product will have its own attributes? and a user can have multiple products?

It is all the same doubt, if I was not clear please ask me to edit the question! thank you from now!

  • What you want is a relationship Many-to-Many? That is: the products will be shared between users or each product will belong to one user?

  • The second option, a user may have multiple products, but these products will not have a standard.

1 answer

1


I think a possible solution would be to create a product attributes table.

Pessoas
-id
-nome

Produtos
-id
-pessoa_id
-nome

Atributos
-id
-produto_id
-nome
-valor

Where the name is attribute can be, for example, color and the value white.

  • Thanks for answering, does that have a specific name ? As I said earlier I will be using Rails, along with Activerecord, I would like to look for more on how to work with it there! :D

  • 1

    If you choose this solution, you will only create three models with 1-to-many (or 1-N) relations. Read about the types of relationships Rails supports here: http://guides.rubyonrails.org/association_basics.html

  • Ball show, I’ll test for sure! valeuu! D

Browser other questions tagged

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