Inheritance and Polymorphism conflicting in ruby on rails -


I have a problem with Ruby on Rails. I have several model squares which can be used from the same class for some common behavior Passes.

The parent class is called a cashable element. One of the children says the result.

I am called a flow related to any child of the cached element, one needs another model. Therefore the element in the flow is called a polymorphic property, for which it is related

When I create a new flow, which falls under a result, element_type is set to "cached element" Which is the "result"

This is confusing because I have many types of cached elements that are stored in different tables, element_id has many different elements.

In short, I should mention the element_type field to name the child's class and not the parent class name.

How can I do this?

field element_type is set to parent class because ActiveRecord allows you to Expecting to use single-table inheritance when received from models. The field will reference the base class because it refers to the table in which each instance is stored.

If the children of Cached Element are stored in their tables, then it may be possible to replace the use of the heritage with the use of the Ruby module, Standard approach for shared logic is to use mix-ins instead of legacy, for example:

  Module cacheable # methods which should be available for all cached models ... ... final result results & l T; ActiveRecord :: Base cacheable # ... end  

Now you can easily use polymorphic associations because you are already doing and element_type Will be set to fair square


Comments

Popular posts from this blog

c++ - Linux and clipboard -

Visual Studio 2005: How to speed up builds when a VSMDI is open? -

booting ubuntu from usb using virtualbox -