single-table-inheritance

Changing type of ActiveRecord Class in Rails with Single Table Inheritance

╄→尐↘猪︶ㄣ 提交于 2019-12-21 03:14:25
问题 I have two types of classes: BaseUser < ActiveRecord::Base and User < BaseUser which acts_as_authentic using Authlogic's authentication system. This inheritance is implemented using Single Table Inheritance If a new user registers, I register him as a User. However, if I already have a BaseUser with the same email, I'd like to change that BaseUser to a User in the database without simply copying all the data over to the User from the BaseUser and creating a new User (i.e. with a new id). Is

Changing type of ActiveRecord Class in Rails with Single Table Inheritance

流过昼夜 提交于 2019-12-21 03:14:12
问题 I have two types of classes: BaseUser < ActiveRecord::Base and User < BaseUser which acts_as_authentic using Authlogic's authentication system. This inheritance is implemented using Single Table Inheritance If a new user registers, I register him as a User. However, if I already have a BaseUser with the same email, I'd like to change that BaseUser to a User in the database without simply copying all the data over to the User from the BaseUser and creating a new User (i.e. with a new id). Is

Hierarchical database model

无人久伴 提交于 2019-12-20 06:49:08
问题 I'm designing a classifieds website about pets that will have 3 (main) categories of ads: A- Sale B- Breeding C- Jobs The problem I'm facing is that all 3 ad categories have some things in common, but they also have some differences. For example, categories A, B and C all have the following in common: category_id ad_id user_id location However, category B ads cannot be classified as "Looking For/For Sale", whereas B & C can. Furthermore, each category will have its own subcategories. For

EF6 - TPH foreign key mapping in derived classes using base class property

自作多情 提交于 2019-12-19 21:46:29
问题 I am using Entity Framework 6.0.2 with an existing database in which tags are stored in a single table that looks like this: Id : int, primary key TagType : string, determine the type of tag, either "usertag" or "movietag" ItemId : int, contains the Id of the item to which is referred (either a User Id or a Movie Id) The following classes describe this situation: public class User { public int Id { get; set; } } public class Movie { public int Id { get; set; } } public abstract class Tag {

EF6 - TPH foreign key mapping in derived classes using base class property

走远了吗. 提交于 2019-12-19 21:46:23
问题 I am using Entity Framework 6.0.2 with an existing database in which tags are stored in a single table that looks like this: Id : int, primary key TagType : string, determine the type of tag, either "usertag" or "movietag" ItemId : int, contains the Id of the item to which is referred (either a User Id or a Movie Id) The following classes describe this situation: public class User { public int Id { get; set; } } public class Movie { public int Id { get; set; } } public abstract class Tag {

EF6 - TPH foreign key mapping in derived classes using base class property

别等时光非礼了梦想. 提交于 2019-12-19 21:46:22
问题 I am using Entity Framework 6.0.2 with an existing database in which tags are stored in a single table that looks like this: Id : int, primary key TagType : string, determine the type of tag, either "usertag" or "movietag" ItemId : int, contains the Id of the item to which is referred (either a User Id or a Movie Id) The following classes describe this situation: public class User { public int Id { get; set; } } public class Movie { public int Id { get; set; } } public abstract class Tag {

Best practices to handle routes for STI subclasses in rails

偶尔善良 提交于 2019-12-17 08:00:05
问题 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

Does single table inheritance results in denormalization

江枫思渺然 提交于 2019-12-14 03:28:52
问题 We're trying to come up with the data model of Payment Method. There can be several kinds of payment methods like Card, Bank Transfer, Wallet, which further can be categorized for e.g. Card into credit/debit cards, Bank Transfer into ACH/SEPA and the like. So this is about modelling inheritance into database tables. One option is to use single table inheritance. Senior folks in my team call single table as denormalized table. But I don't understand why? I don't see any insert/delete/update

Single Table Inheritance with Factory Girl in Rails

僤鯓⒐⒋嵵緔 提交于 2019-12-12 11:16:47
问题 I'm making a Rails 4.0.1 app using Capybara and FactoryGirl but I'm having trouble getting my tests to work correctly. I'm using single table inheritance to make a Collection < ActiveRecord::Base and a VideoCollection < Collection model. When using Factory Girl in my tests, the models don't seem to get instantiated as they should. The Details: When I visually inspect a view in my browser that I'm testing, it displays the collection properly. When I run print page.html in the test for the same

Broken Rails Routes after implementing Single Table Inheritance

☆樱花仙子☆ 提交于 2019-12-12 08:15:02
问题 I have implemented single table inheritance for a person class class Person < ActiveRecord::Base end class Teacher < Person end class Student < Person end class Outsider < Person end And the create person seems to work creating Teacher, Student or Person according to the what is chosen in the form.select and the type attribute is added. However, I seem to have broken the routes <%= link_to 'Edit', edit_person_path(@deal) %> | <%= link_to 'Back', persons_path %> They seem to point to teacher