single-table-inheritance

Spring: controller inheritance using @Controller annotation

泄露秘密 提交于 2019-12-07 01:33:06
问题 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 instance of User, registered or otherwise. However, I have no idea how I would do this since it seems that by using controllers purely using the @Controller

Twig instanceof for inheritance objects

时光总嘲笑我的痴心妄想 提交于 2019-12-06 17:07:37
问题 I am using the following feature from propel http://www.propelorm.org/documentation/09-inheritance.html. I am also using Symfony2 and Twig I have a class structure using the above feature that looks something like this class Event {} class Birthday extends Event {} class Walking extends Event {} now I pass an event object to a twig template and I want to know what type of event it is For instance I want to display an image of a cake if its a birthday and I want to display map routes if its

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

一曲冷凌霜 提交于 2019-12-06 15:22:55
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 => :properties map.resources :properties Tomas Markauskas A simple way to fi the problem would be to create a

How to map collection of each subclass from same hierarchy onto one owning class?

天涯浪子 提交于 2019-12-06 12:07:20
问题 Does anyone know how to map a collection of each subclass from the same hierarchy onto one owning class, using JPA 2.0 annotations, backed by Hibernate 4.0.0.Final? Bit convoluted, so here's an example. Hierarchy classes look like this: @Entity @Cacheable(true) @Table(name = "hierarcicals") @Inheritance(strategy=InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name = "class", discriminatorType = DiscriminatorType.STRING) public abstract class MySuperClass { ... @Entity @DiscriminatorValue(

DataMapper - Single Table Inheritance

≯℡__Kan透↙ 提交于 2019-12-06 05:21:11
Could Some one please explain to me what is going on here? This is an example that I put together to show y'all whats up: class Person include DataMapper::Resource property :id, Serial property :type, Discriminator property :name, String property :age, Integer end class Male < Person end class Father < Male property :job, String end class Son < Male end class Female < Person end class Mother < Female property :favorite_song, String end class Daughter < Female end DataMapper.auto_upgrade! If I call Person.all I get: Person.all => [#<Son @id=1 @type=Son @name="Mike" @age=23 @status=nil>, #<Son

How do I handle authentication with Devise when using multiple models in Rails 3.2 App

[亡魂溺海] 提交于 2019-12-05 16:05:24
问题 I'm working on a Rails 3.2 app where I use Devise for authentication. I decided to try single table inheritance for managing user roles, but I quickly ran into a problem. I currently have three User models, User < ActiveRecord , Admin < User and Collaborator < User . Admin and Collaborator share most User columns, but they have slightly different behaviors and privileges. My models currently looks like this: class User < ActiveRecord::Base devise :database_authenticatable, :registerable,

Rails devise add fields to registration form when having STI

随声附和 提交于 2019-12-05 06:41:47
问题 Here is my models: class User < ActiveRecord::Base has_one :worker, :class_name => 'Worker', :foreign_key => :worker_id devise :database_authenticatable accepts_nested_attributes_for :worker attr_accessible :worker_id, :email, :password, :password_confirmation, :remember_me, :workers_attributes, :worker_attributes, :name, :worker end class Worker < User devise :database_authenticatable, :registerable belongs_to :user attr_accessible :name, :worker, :workers end I am trying to add the field

Spring: controller inheritance using @Controller annotation

。_饼干妹妹 提交于 2019-12-05 04:57:24
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 instance of User, registered or otherwise. However, I have no idea how I would do this since it seems that by using controllers purely using the @Controller annotation each controller is free to define their request handling method however they like. Would

JVM crashing when using any other Hibernate inheritance strategy besides SINGLE_TABLE

安稳与你 提交于 2019-12-05 01:26:56
问题 Ok, this is probably a longshot but here goes. In Java (JRE 1.6.0_26-b03) I have two classes, SuperControl and its subclass SubControl . They both need to be persistent objects and I'm using Hibernate Annotations to achieve this. I have approximately 210 classes that are being persisted correctly. Except one isn't. My problem is that SubControl refuses to inherit in any way besides SINGLE_TABLE . When I say "refuses", I mean that the entire JRE crashes . This is a bit problematic because I'd

How to model different users in Rails

痴心易碎 提交于 2019-12-05 00:35:35
问题 Question I have a User model with authorisation and authentication logic built. Now I realise I have three different types of users. I want to store different information about each of them. What is the best way to handle this in Rails? Thoughts based on current reading I've looked at STI but from what I've read feel it is inappropriate because I'll end up with a lot of NULL fields in my database. Ideally I'd like to not duplicate the authentication / authorisation logic for each of the three