polymorphic

Rails Model for Playlist that can contain tracks and albums using polymorphism

I struggle to find a model how to store a playlist with different type of items on it in Rails. Consider I have class Track end class Album has_many :tracks end class PlaylistItem belongs_to :playable belongs_to :playlist end class Playable belongs_to :playable, :polymorph => true end class Playlist has_many :playlist_i...

java polymorphic binary search tree

how can i implement a polymorphic binary search tree (that makes use of EmptyTree and NonEmptyTree) without using downcasting or class checking? ...

CPU emulator on C for assembler

I have a problem; I´m working on a little security application. I received an array, i.e. a sequence of bytes, and such bytes can be interpreted as assembly code. So, my question is... Does someone knows a library that I can use on my application and which can execute this bytes sequence and show what it does (or something like that) ? ...

accepts_nested_attributes

I'm trying to use a comment style model which is attached to another model but I keep getting the error: Review(#2171315060) expected, got Array(#2148226700) With params: Processing PlacesController#create (for 127.0.0.1 at 2010-04-15 18:57:02) [POST] Parameters: {"commit"=>"Submit", "action"=>"create", "destination_id"=>"3...

using UUID as primary key in rails and polymorph relationships

I'm creating a rails 3 application that will be decentralized and I need to use UUID as primary key for my tables, what would be the best gem, plugin for the Job. I also would like to know if it is possible to make in ActiveRecord polymorphic relationships without using the polymorphicable_type column for it, given the case that I'm usin...

How ugly is my code implementing polymorphic models?

I am using Polymorphic Models. Simple Question: My code below works without using this line below, which I see in other people's code. What is it supposed to do? #super(GeneralModel, self).__init__(*args, **kwargs) Messy Question: I have a feeling my code below, although it seems to work, is not the most beautiful solution. Synopsi...

Django: way to test what class a generic relation content_object is?

In my project I have a class, NewsItem. Instances of NewsItem act like a wrapper. They can be associated with either an ArtWork instance, or an Announcement instance. Here's how the NewsItem model looks: class NewsItem(models.Model): content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() content_o...

Polymorphic Paperclip Interpolations

I'm using the Polymorphic fork of Paperclip in Rails, but have been having some massive problems with regards to the overwriting of unique filenames. No matter whether I put a time-stamp (more on that in a second) or the id of the asset in the URL, if a file with the same name is uploaded subsequently, then the previous one is overwritte...

Using Ruby on Rails, can a polymorphic database be created in a few steps (with polymorphic associations)?

I thought it could be created in a few steps but it can't yet: rails poly cd poly ruby script/generate scaffold animal name:string obj_type:string obj_id:integer rake:migrate ruby script/generate scaffold human name:string passportNumber:string rake:migrate ruby script/generate scaffold dog name:string registrationNumber:string rake:...

Ruby on Rails: How do you seed the *_type column in polymorphic models?

I have a lot of data that I'm trying to seed into a polymorphic model in Rails 2.3.8. The association for all of the data is with the County model. The data looks like: data = Datum.create([ ... { :value => '14389', :value_type => County, :value_id =>'3103'}, { :value => '59013', :value_type => County, :value_id =>'3105'}, { :va...

Querying a polymorphic association

I have a polymorphic association like this - class Image < ActiveRecord::Base has_one :approval, :as => :approvable end class Page < ActiveRecord::Base has_one :approval, :as => :approvable end class Site < ActiveRecord::Base has_one :approval, :as => :approvable end class Approval < ActiveRecord::Base belongs_to :approvable...

Using metamorphic code to reduce boilerplate

Has anyone seen metamorphic code -- that is, code that generates and runs instructions (including IL and Java Bytecode, as well as native code) -- used to reduce boilerplate code? Regardless of the application or language, typically one has some database code to get rows from the database and return a list of objects. Of course, there ...

sqlalchemy - double polymorphic inheritance problem

Hi, I've got a class mapping with two polymorphic inheritance : #test classes class AbstractA(Base): __tablename__ = "abstract_a" id = Column(Integer, primary_key=True) class_name = Column('class_name', String(50)) __mapper_args__ = { 'polymorphic_on': class_name, } #some stuff here class AbstractB(Abs...

Polymorphic assosciation question

Hello! In my Rails app I have models that look something like this: class Blog < ActiveRecord::Base has_many :posts end class Post < ActiveRecord::Base belongs_to :blog end class Comment < ActiveRecord::Base belongs_to :commentable, :polymorphic => true end What I'm having problem with now is finding all comments under a spec...

Using polymorph many-to-many self referencing relation with attributes on the relation in rails

Hi, I'd like to create a self referencing relation in rails. I have a Person model, and the person should have masters and pupils with same Person object. So far I tried: class Person <ActiveRecord::Base has_many :relationships, :dependent => :destroy has_many :masters, :through => :relationships, :conditions => "status='master'"...

Problem with routing rails 3.0.0 and --force-plural

Hi, sorry for bad English. For example i execute script/rails generate scaffold goods title:string --force-plural Then i follow to http://localhost:3000/goods/new and got error undefined method `goods_index_path' for #<#:0x7f1e7cb32530> I found some line involved in this behavour in polymorphic_routes.rb, but can't understand what ...

Keeping type generic without η-expansion

What I'm doing: I'm writing a small interpreter system that can parse a file, turn it into a sequence of operations, and then feed thousands of data sets into that sequence to extract some final value from each. A compiled interpreter consists of a list of pure functions that take two arguments: a data set, and an execution context. Each...