polymorphic

NHibernate child to polymorphic parent mapping

Hi, Using NHibernate 1.2.0. I have a parent-child relationship with a polymorphic parent class. The child has a many-to-one "Parent" property referencing the base parent class. In HQL, starting from the child class, I need to access a property of one of the derived parent types. Something like: select parentA.SomeProperty from Chil...

how to create reviews using polymorphic associations

Hello, I have three models that can all have a Review and each review must belong to a User. I am using polymorphic associations :as => :reviewable but I am not sure where I should put the logic for creating a review for each model. I would assume that the CRUD for each review should be handled by the reviews_controller (or nested attri...

Polymorphic has_many self-referential

Hello there, I am having trouble getting this to work. My problem is. I have A number of models (Article, Video, Photo) Now I am trying to create a related_to association, such that An article can have many other articles, videos and photos related to it. As can videos and photos. Heres what I have tried module ActsAsRelatable def...

Inheritance Mapping with Fluent NHibernate

Given the following scenario, I want map the type hierarchy to the database schema using Fluent NHibernate. I am using NHibernate 2.0 Type Hierarchy public abstract class Item { public virtual int ItemId { get; set; } public virtual string ItemType { get; set; } public virtual string FieldA { get; set; } } public abstra...

Polymorphic Association doesn't save ClassName (without STI), any hints??

Hi, I have two models, one called Notes and one called Comments. Comments can be associated to many other models so I use a polymorphic association. In the schema.rb it looks like this: create_table "comments", :force => true do |t| t.text "body" t.integer "user_id" t.integer "commentable_id" t.integer "commentable_type" t.dat...

polymorphic associations and routing

Hi I am very new to rails and am having a problem with routing when using polymorphic associations. On I have a link "Add Comment" on the page installations/1/onposts/2 the link then goes to onposts/2/comments, this works and you can add a comment on this page, when you submit it just redirects to stay on the same page. I want to have a...

How to access and submit related polymorphic models in the same form, in Rails?

Suppose I have 3 models, Car, Motorcycle and Truck, and for each I have to enter a bunch of stuff, such as a list of known previous owners, traffic tickets, license plates, etc. So I created a model for each (PreviousOwners, PreviousPlates, etc) and set up polymorphic associations for the related models. The problem is, how can I enter ...

Rails: Polymorphic or not?

Considering the following resources with their corresponding relationships: Site has_many :page has_many :groups has_many :projects Group belongs_to :site has_many :pages Project belongs_to :site has_many :pages Is it good to make Page model polymorphic or leave individual foreign keys? **Scenario 1 (Polymorphic)** Page pa...

Rails: Resources_Controller/ Resource_Controller/ Make_Resourceful with Subdomain_Fu

I need to use one of the resourceful controllers plugins - resources_controller/ resource_controller/make_resourceful as I have several polymorphic models and the models have to be either initialized/build depending on the route. For example: www.example.com/groups/1/pages www.example.com/projects/1/pages where page acts as polymorp...

Database and relationship design when subclassing a model.

I have a model "Task" which will HABTM many "TaskTargets". When it comes to TaskTargets however, I'm writing the base TaskTarget class which is abstract (as much as can be in Rails). TaskTarget will be subclassed by various different conceptualizations of anything that can be the target of a task. So say, software subsystem, customer ...

Generating a unique file path with Polymorphic Paperclip

I'm running into an issue with different users uploading files with the same name being overwritten with the Polymorphic Paperclip plugin. What I'd like to do is inject the current user's ID into the URL/path. Is this possible? Would I be better off generating a random name? Here are my current :url and :path parameter values in asset.r...

has_many :through, nested polymorphic relations

Is there a way to directly reference (using rails directly, without resorting to a lot of custom SQL) a relation that is nested behind a polymorphic relation? In the below example, is there a way to define a has_many relation in User that references LayerTwo? I'd like to do (in User) has_many :layer_twos, :through => layer_ones but...

rails way to transfer polymorphic object through url

how do i pass a polymorphic object to another controller? for example redirecting from messages/1/ to requests/new?object_type=message&object_id=1 or, second example, from files/154/ to requests/new?object_type=file&object_id=154 is redirect_to new_request_path(:object_type => params[:controller].classify, :object_id => params[:id...

Linq to sort lists of different kind

I am trying to make a log viewer displaying events from different sources but ordered by a time stamp. I have a felling I can use C# Linq for this but how ? example: I have one list of events read from files into a strig list sorted by a datetime stamp. Another source of events are database inserts for which I use Linq to extract the...

How to find polymorphic relation

class Item < ActiveRecord::Base belongs_to :rulable, :polymorphic => true end class foo < ActiveRecord::Base has_many :items, :as => rulable end class bar < ActiveRecord::Base has_many :items, :as => rulable end What is the best way to find items belonging to a foo? I'm currently using something like this: f = Foo.find 1 Item.find_by_...

Rails - embedded polymorphic comment list + add comment form - example?

Hey, all. Working on my first Rails app. I've searched all around - read a bunch of tutorials, articles, and forum posts, watched some screencasts, and I've found a few examples that come close to what I'm trying to do (notably http://railscasts.com/episodes/154-polymorphic-association and ep 196 about nested model forms), but not exac...

Properly mapping a polymorphic relationship with NHibernate

I am trying to create a table-per-hierarchy mapping using NHibernate 2.0.1. I have a base class with properties that exist for each subclass that other classes inherit from. All of these objects are persisted to one table called Messages that contain all of the possible fields for each class. There is a SourceID which is the discriminat...

Rails generate url from array with parameters

Hi I wondered if there's some way to do this polymorphic_path([@page, @image]) but like this polymorphic_path([@page, :image_id => 1]) It's for the purposed of refactoring where I'd like to throw various params into the array and where they're null, they're ignored, but otherwise they generate the relevant nested url. Thanks in ...

ActiveScaffold: How to create a drop-down select for polymorphic association?

I'm trying to create a drop-down select box for a polymorphic association with ActiveScaffold. I have: class Award belongs_to :sponsorship, :polymorphic => :true end class Organization has_many :awards, :as => :sponsorship end class Individual has_many :awards, :as => :sponsorship end While trying to create a select drop-down...

Polymorphic Paperclip overwriting files with the same names

Hi, in Rails using the Polymorphic version of Paperclip, the default saving technique means that files with the same name overwrite each other. Including the :id in the path and URL doesn't work as it just overwrites the earlier file with the old :id. I've tried interpolations using a time-stamp, but it just looks for the current time w...