single-table-inheritance

Hibernate trouble: INSERT instead of UPDATE when using Inheritance:SINGLE_TABLE and SecondaryTables

对着背影说爱祢 提交于 2019-12-09 22:34:58
问题 I have implemented inheritance hierarchy using SINGLE_TABLE with SecondaryTables. This works otherwise, but when my secondary table's field(s) are empty (= null in Oracle), next update to the entity fails since Hibernate thinks it should INSERT to the table when it should UPDATE. Example: CREATE TABLE TASK ( ID NUMBER(10) NOT NULL , TYPE NUMBER(1) NOT NULL , STATUS NUMBER(1) NOT NULL , CONSTRAINT TASK_PK PRIMARY KEY (ID) ENABLE); CREATE TABLE SUB_TASK ( ID NUMBER(10) NOT NULL , TEXT VARCHAR2

has_many and single table inheritance

心已入冬 提交于 2019-12-09 12:35:48
问题 I have a has_many relationship between two entities, Feeds and Posts. I also have specific types of posts, Videos and Photos. This is structured in the database using single table inheritance. Right now I have my Feed model specifying a has_many relationship between Feeds and Posts (including the subtypes) class Feed < ActiveRecord::Base has_many :posts has_many :photos has_many :videos Is there a better, more conventional way to specify this? Or is what I have as simple as it can get? 回答1:

Hibernate: Parent/Child relationship in a single-table

☆樱花仙子☆ 提交于 2019-12-09 11:49:38
问题 I hardly see any pointer on the following problem related to Hibernate. This pertains to implementing inheritance using a single database table with a parent-child relationship to itself. For example: CREATE TABLE Employee ( empId BIGINT NOT NULL AUTO_INCREMENT, empName VARCHAR(100) NOT NULL, managerId BIGINT, CONSTRAINT pk_employee PRIMARY KEY (empId) ) Here, the managerId column may be null, or may point to another row of the Employee table. Business rule requires the Employee to know about

Can nested attributes be used in combination with inheritance?

亡梦爱人 提交于 2019-12-09 03:13:36
问题 I have the following classes: Project Person Person > Developer Person > Manager In the Project model I have added the following statements: has_and_belongs_to_many :people accepts_nested_attributes_for :people And of course the appropriate statements in the class Person . How can I add a Developer to a Project through the nested_attributes method? The following does not work: @p.people_attributes = [{:name => "Epic Beard Man", :type => "Developer"}] @p.people => [#<Person id: nil, name:

Rails devise registration form when having STI

六月ゝ 毕业季﹏ 提交于 2019-12-09 00:06:18
问题 I dont know how to create a worker and a association. So i am able to link those together. I have a type colulm in user. This is my form(http://localhost:3000/workers/sign_up): <h2>Create Worker</h2> <%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %> <%= devise_error_messages! %> <p><%= f.label :email %><br /> <%= f.text_field :email %></p> <p><%= f.label :kodeord %><br /> <%= f.password_field :password %></p> <p><%= f.label :bekraeft_kodeord %>

Table per hierarchy inheritance with POCO entities in Entity Framework 4

巧了我就是萌 提交于 2019-12-08 07:28:33
问题 Our organization is looking to standardize on Entity Framework once v4 comes out. As a result, I am looking at what it would take to migrate our application that uses NHibernate for persistence to EF4 using POCO support. In a couple of places we use single table inheritance (also known as Table Per Hierarchy). I have been unable to get it to work using the following. Payment (base class [should be abstract but having trouble there as well]) CreditCardPayment (concrete implementation)

Different routes but using the same controller for model subclasses in Rails

爷,独闯天下 提交于 2019-12-08 06:40:54
问题 I have a Model Property which has subclasses using STI, and which I would like all to use the same controller with only different view partials depending on the subclass. Property Restaurant < Property Landmark < Property It works find except I'm not sure how to discern the subclass inside the controller to render the correct view. Ie. /restaurants works and goes to the properties controller but I can't tell that they want the Restaurant subclass? map.resources :restaurant, :controller =>

STI Inheiritance in Rails. Issues with find

匆匆过客 提交于 2019-12-07 19:25:12
问题 I am having an issue with searching for records in my STI table due to my inheritance structure class User < ActiveRecord::Base class LegacyUser < User class AuthUser < User class SuperUser < AuthUser class FieldUser < AuthUser class ClientAdmin < AuthUser The problem is that find does not work for the AuthUser Model. The query is looking for type "AuthUser" and does not include the other three possibilities. Edit: While playing around with this it started to work but only for ClientAdmin and

How to make Rails 3 reload STI classes in development mode?

◇◆丶佛笑我妖孽 提交于 2019-12-07 18:19:56
问题 After switching to Rails 3, I noticed that I have to reboot my server to make STI model classes reload with each request. For example, suppose I have this: # app/models/vehicle.rb class Vehicle < ActiveRecord::Base end # app/models/car.rb class Car < Vehicle end If I make a change to Vehicle , the change is loaded on the next request. But if I make a change to Car , I have to reboot my server for it to load. Any ideas on fixing this? I'm running WEBrick, but I'm not committed to it. 回答1: We

Change ActiveRecord::Base.inheritance_column in a rails app

六月ゝ 毕业季﹏ 提交于 2019-12-07 03:35:57
问题 I want to use Single Table Inheritance using a column other than type . According to the Rails documentation - http://api.rubyonrails.org/classes/ActiveRecord/Base.html, I can do this by modifying ActiveRecord::Base.inheritance_column . How can I do this? 回答1: Try the following: class MyModel < ActiveRecord::Base self.inheritance_column = 'column_that_is_not_type' end Your migrations should work everywhere. 回答2: @Vidya's answer is correct but a better way is: class MyModel < ActiveRecord: