single-table-inheritance

Multiple Table Inheritance vs. Single Table Inheritance in Ruby on Rails

别说谁变了你拦得住时间么 提交于 2020-11-25 06:04:33
问题 I have been struggling for the past few hours thinking about which route I should go. I have a Notification model. Up until now I have used a notification_type column to manage the types but I think it will be better to create separate classes for the types of notifications as they behave differently. Right now, there are 3 ways notifications can get sent out: SMS, Twitter, Email Each notification would have: id subject message valediction sent_people_count deliver_by geotarget event_id list

How to structure this so I get all the benefits from STI with none of the consequences? (Pretty irresponsible, I know.)

僤鯓⒐⒋嵵緔 提交于 2020-01-04 06:27:29
问题 Say I have the following example of associations in a Rails app: I'm considering combining the *Posting models under STI. One problem with STI is the potential for many attributes that are only related to one subclass (i.e., a lot of denormalized nil values). This is especially worrisome when your subclasses and going to evolve and grow in the future. I've read a few related posts (such as this), however, as you can see in my example, the potential subclass-specific fields will not

Rails attr_accessible does not work for :type?

只愿长相守 提交于 2020-01-03 16:56:39
问题 Im trying set the single table inheritance model type in a form. So i have a select menu for attribute :type and the values are the names of the STI subclasses. The problem is the error log keeps printing: WARNING: Can't mass-assign these protected attributes: type So i added "attr_accessible :type" to the model: class ContentItem < ActiveRecord::Base # needed so we can set/update :type in mass attr_accessible :position, :description, :type, :url, :youtube_id, :start_time, :end_time validates

Rails Question: belongs_to with STI — how do i do this correctly?

我怕爱的太早我们不能终老 提交于 2020-01-02 01:02:24
问题 I've been playing around with STI and belongs_to / has_many relationships and I'm a bit confused. I have a few questions based on a model configuration similar to: class Parental < ActiveRecord::Base end class Mother < Parental has_many :babies end class Father < Parental has_many :babies end class Baby < ActiveRecord::Base belongs_to :?????? end What should Baby belong_to? In terms of a migration, what should i name/add for foreign key on the babies table? I've had a hard time researching

MySQL / Rails Performance: One table, many rows vs. many tables, less rows?

巧了我就是萌 提交于 2020-01-01 19:21:14
问题 In my Rails App I've several models dealing with assets (attachments, pictures, logos etc.). I'm using attachment_fu and so far I have 3 different tables for storing the information in my MySQL DB. I'm wondering if it makes a difference in the performance if I used STI and put all the information in just 1 table, using a type column and having different, inherited classes. It would be more DRY and easier to maintain, because all share many attributes and characteristics. But what's faster?

Can a Discriminator Column be part of the Primary Key in Doctrine2?

眉间皱痕 提交于 2020-01-01 12:29:25
问题 I'm using Single Table Inheritance in Doctrine2 to store OAuth credentials for multiple services. I'd like to use the service's id as the primary key; however, that's not unique across all services. I've setup the database to use the discriminator column and the service's id as the primary key, but I can't find a way to make Doctrine use the discriminator column as the key (in addition to the discriminator column). I'm using docblock annotations, and if I add the discriminator column as an

Need classic mapper example for SqlAlchemy single table inheritance

本小妞迷上赌 提交于 2019-12-31 04:39:04
问题 I found an example of how to do single table inheritance using Class mappings. http://docs.sqlalchemy.org/en/latest/orm/inheritance.html#single-table-inheritance But for the life of me, I cannot find an example of how to do this with classic mapper so that I can keep my classes and persistent mappings separate. How do I convert this example into classic mapping? I am clear on creating the tables, just not sure how to actually structure the mapper. In the example, there are the following types

Single Table Inheritance or Class Table Inheritance?

假装没事ソ 提交于 2019-12-30 06:03:30
问题 I'm reading about Class Table Inheritance (CTI) and finding I prefer it overall. The question I have is, is there any specific use case for Single Table Inheritance (STI) where you'd use that over CTI? I read http://rhnh.net/2010/07/02/3-reasons-why-you-should-not-use-single-table-inheritance and as far as I know, it's solid. The use case for STI being a difference in behaviour but not data. 回答1: I would like to point you to a great article I have found that explains with clarity why and when

Rails database setup Polymorphism

我只是一个虾纸丫 提交于 2019-12-25 18:28:39
问题 We have to create a request system which will have roughly 10 different types of requests. All of these requests will belong to the 'accounting' aspect of our application. Therefore we've called them "Accounting requests". All requests share maybe only a few columns and each has up to 20 columns individually. We started to wonder if having separate tables for each request type would be practical in terms of speed when we start to have to do very complicated joins or queries, for example,

Loop over related model's children in Django template

自作多情 提交于 2019-12-25 01:37:59
问题 I have a model for a company. Then I have a base model for company posts. It contains common posts attributes. An attribute is the company that publishes the posts. It refers to the Company model with a ForeignKey. Finally I have a child model (based on the CompanyPost base model) for posts of type A: class Company(models.Model): name = models.CharField(...) ... class CompanyPost(models.Model): company = models.ForeignKey(Company,...) ... class PostA(CompanyPost): name = ... In a template I