single-table-inheritance

STI and polymorphs

点点圈 提交于 2019-11-30 02:49:57
问题 I have problem with my code class Post < ActiveRecord::Base end class NewsArticle < Post has_many :comments, :as => :commentable, :dependent => :destroy, :order => 'created_at' end class Comment < ActiveRecord::Base belongs_to :commentable, :polymorphic => true, :counter_cache => true end And on attempt go get comments for some NewsArticle i see in logs something like Comment Load (0.9ms) SELECT "comments".* FROM "comments" WHERE ("comments"."commentable_id" = 1 and "comments"."commentable

Rails STI: How to change mapping between class name & value of the 'type' column

我的未来我决定 提交于 2019-11-29 09:21:41
Because of company rules I can't use our domain class names; I am going to use an analogy instead. I have a table called projects which has a column called 'type' with possible values as 'indoor' & 'outdoor'. Records having indoor and outdoor have clear functionality separation and would fit pretty neatly as a STI implementation. Unfortunately I can't change the type-names and can't add classes inside the global namespace. Is there a way to specify a different value for 'type'? Note: I am not trying to use a different column name instead of 'type' for STI. I am looking to have a different

Creating “feeds” from multiple, different Rails models

人走茶凉 提交于 2019-11-29 04:35:42
问题 I'm working on an application that has a few different models (tickets, posts, reports, etc..). The data is different in each model and I want to create a "feed" from all those models that displays the 10 most recent entries across the board (a mix of all the data). What is the best way to go about this? Should I create a new Feed model and write to that table when a user is assigned a ticket or a new report is posted? We've also been looking at STI to build a table of model references or

How to get the DiscriminatorValue at run time

99封情书 提交于 2019-11-28 08:09:53
We have the following classes @Entity @Inheritance(strategy = InheritanceType.SINGLE_TABLE) // optional annotation as this is default @DiscriminatorColumn(name = "apType", discriminatorType = DiscriminatorType.STRING, length = 255) @DiscriminatorValue("AP") public class ApplicationProcess { } And this @Entity @DiscriminatorValue("APS") public class ApplicationProcessScheme extends ApplicationProcess { } Now I need to know at runtime if the ApplicationProcess is of DiscriminatorValue AP or APS . Since this is automatically handled by jpa, I have no way of getting this value. We are calling a

Single Table Inheritance in Django

强颜欢笑 提交于 2019-11-28 08:09:31
Is there explicit support for Single Table Inheritance in Django? Last I heard, the feature was still under development and debate. Are there libraries/hacks I can use in the meantime to capture the basic behavior? I have a hierarchy that mixes different objects. The canonical example of a corporation structure with an Employee class, subclasses for types of employees, and a manager_id (parent_id) would be a good approximation of the problem I am solving. In my case, I would like to represent the idea that an employee can manage other employees while being managed by a different employee.

Rails: Using Devise with single table inheritance

前提是你 提交于 2019-11-28 03:24:48
I am having a problem getting Devise to work the way I'd like with single table inheritance. I have two different types of account organised as follows: class Account < ActiveRecord::Base devise :database_authenticatable, :registerable end class User < Account end class Company < Account end I have the following routes: devise_for :account, :user, :company Users register at /user/sign_up and companies register at /company/sign_up . All users log in using a single form at /account/sign_in ( Account is the parent class). However, logging in via this form only seems to authenticate them for the

Rails STI: How to change mapping between class name & value of the 'type' column

空扰寡人 提交于 2019-11-28 02:43:13
问题 Because of company rules I can't use our domain class names; I am going to use an analogy instead. I have a table called projects which has a column called 'type' with possible values as 'indoor' & 'outdoor'. Records having indoor and outdoor have clear functionality separation and would fit pretty neatly as a STI implementation. Unfortunately I can't change the type-names and can't add classes inside the global namespace. Is there a way to specify a different value for 'type'? Note: I am not

Best practices to handle routes for STI subclasses in rails

我是研究僧i 提交于 2019-11-27 09:58:32
My Rails views and controllers are littered with redirect_to , link_to , and form_for method calls. Sometimes link_to and redirect_to are explicit in the paths they're linking (e.g. link_to 'New Person', new_person_path ), but many times the paths are implicit (e.g. link_to 'Show', person ). I add some single table inheritance (STI) to my model (say Employee < Person ), and all of these methods break for an instance of the subclass (say Employee ); when rails executes link_to @person , it errors with undefined method employee_path' for #<#<Class:0x000001022bcd40>:0x0000010226d038> . Rails is

Single Table Inheritance in Django

為{幸葍}努か 提交于 2019-11-27 05:47:10
问题 Is there explicit support for Single Table Inheritance in Django? Last I heard, the feature was still under development and debate. Are there libraries/hacks I can use in the meantime to capture the basic behavior? I have a hierarchy that mixes different objects. The canonical example of a corporation structure with an Employee class, subclasses for types of employees, and a manager_id (parent_id) would be a good approximation of the problem I am solving. In my case, I would like to represent

Rails: Using Devise with single table inheritance

本小妞迷上赌 提交于 2019-11-27 05:07:40
问题 I am having a problem getting Devise to work the way I'd like with single table inheritance. I have two different types of account organised as follows: class Account < ActiveRecord::Base devise :database_authenticatable, :registerable end class User < Account end class Company < Account end I have the following routes: devise_for :account, :user, :company Users register at /user/sign_up and companies register at /company/sign_up . All users log in using a single form at /account/sign_in (