single-table-inheritance

single table inheritance: must all classes in hierarchy have same properties?

I have the following class Item < ActiveRecord::Base end class Talk < Item end with the migration class CreateItems < ActiveRecord::Migration def self.up create_table :items do |t| t.string :type t.string :name t.text :description t.time :start_time t.time :duration t.timestamps end en...

Propel Single Table Inheritance Issue

I have a table called "talk", which is defined as abstract in my schema.xml file. It generates 4 objects (1 per classkey): Comment, Rating, Review, Checkin It also generates TalkPeer, but I couldn't get it to generate the other 4 peers (CommentPeer, RatingPeer, ReviewPeer, CheckinPeer), so I created them by hand, and made them inherit ...

Rails and Hobo with Single Table Inheritance problem

I'm getting an error when running db:setup for my Hobo project with a clean database. I have two models, A and B, where B extends A through single-table-inheritance. Creating everything works. But if I start with a fresh database, rake fails with an error: $ rake db:setup ... rake aborted! Table as does not exist Here are the steps I ...

Re: PoEAA Book, by Fowler: p.283 (Single Table Inheritance Example - Updating an Object)- How does the row[] array get into the db?

This question is about a specific example (in the book called Patterns Of Enterprise Application Architecture, by Martin Fowler) on page 283 - (Single Table Inheritance Example - Updating an Object) I can see Mapper::Update() method invoking CricketerMapper::Save() method, which First, invokes AbstractPlayerMapper::Save() to assign ro...

has_many with multi-level hierarchy and single table inheritance

In my Rails app I have a multi-level hierarchy of the following kind: class Vehicle < ActiveRecord::Base end class RoadVehicle < Vehicle end class Car < RoadVehicle end class Buss < RoadVehicle end Then I have a class referencing the middle level like so: class Garage < ActiveRecord::Base has_many :road_vehicles end In this simpl...

Spring: controller inheritance using @Controller annotation

I'd like to be able to create a base controller in my Spring app that, among other things, determines if a user is a registered user or not. This base controller, following the template design pattern, would contain an abstract protected method that controller subclasses would implement. The abstract method would have passed to it an ...

Rails STI using ONE form

I have a form that allows me to add files of different formats to a stream. So, a stream is made up of many files, these files are XML files but basically have different schemas. I have one form that allows the user to add whatever file they want, I am using STI (which works great when data is already in the table), my trouble is adding ...

linq to sql and inheritance question

Does anyone know how to to get the inheritance code for a specific type (single table inheritance in Linq to sql) ? When I create a new entity B (which is inherited from A), I would like to write some code in A, that is valid for all objects inherited from A. However, when you create a new entity B, it's inheritance code is not yet fil...

Creating "feeds" from multiple, different Rails models

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...

How to obtain action level protection using Authlogic and STI?

Given that it is well-documented how to use before_filter for a single user classification, I'm having trouble getting action-level protection for multiple user types. Let me explain: I've got something like this... class ApplicationController < ActionController::Base class << self attr_accessor :standard_actions end @stand...

TypeError when trying to use observers and STI

I'm trying to follow along with the thread on implementing an achievement system (located at http://stackoverflow.com/questions/885277/how-to-implement-an-achievement-system-in-ror), and am running into a TypeError when the object is saved and the method awarded? gets called. The error looks like: TypeError (can't dump anonymous class C...

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

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. ...

Avoiding STI in Rails

class User < ActiveRecord::Base has_one :location, :dependent => :destroy, :as => :locatable has_one :ideal_location, :dependent => :destroy, :as => :locatable has_one :birthplace, :dependent => :destroy, :as => :locatable end class Location < ActiveRecord::Base belongs_to :locatable, :polymorphic => true end class IdealLocatio...

Saving and retrieving inherited types with LINQtoSQL and Business Objects

I have an abstract EventBase class and some inherited event types, along with an Event class. Each event type has its own unique columns. In my data layer, I have a GetEvents method that simply does: from e in db.Events select new Event {...values...}; EventType is an enum which matches up to an EventTypes table I want GetEve...

Trying to return various models with Ruby Activescaffold find on models with inheritance

class Promotion def self.get_todays_promotions # Promotion is a parent model, having child models e.g. # DiscountPromotion, VoucherPromotion, etc. # they all use a single table called promotions # (and having 'type' field explaining which model they belong to) promotions = self.find(:all, :conditions => [Promotion....

Rails Single Table Inheritance with HABTM Fixture in unit testing returning NoMethodError: undefined method `singularize'

Imagine a model structure as follows: models/cross_sell_promotion.rb class CrossSellPromotion < Promotion has_and_belongs_to_many :afflicted_products, :join_table => :promotion_afflicted_products, :foreign_key => 'promotion_id', :association_foreign_key => 'product_id', :class_name => 'Product' has_and_belongs_to_...

Hibernate: Parent/Child relationship in a single-table

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_empl...

mongo mapper with STI with more than one type?

I have a series of models all which inherit from a base model Properties For example Bars, Restaurants, Cafes, etc. class Property include MongoMapper::Document key :name, String key :_type, String end class Bar < Property What I'm wondering is what to do with the case when a record happens to be both a Bar & a Restaurant? I...

Using STI path with same controller

I am using STI and am wondering, do I have to have a separate controller for each model? I have a situation where I only use the create and edit actions for one model in the STI relationship, but I get an 'undefined method' error if I try to do a form for. More specifically, I have two models that inherit from List: class RegularList ...

Is there a way to model table inheritance using MySQL Workbench?

Is there a way to model table inheritance using MySQL Workbench? I'd like the ERD to look similar to the left side of this image: ...