STI with many to many association

R

Rodrigo Pavano

[Note: parts of this message were removed to make it a legal post.]

Hello!

Im using ruby 1.9.2 and Rails 3.0.3.

I have the following models

class Property < ActiveRecord::Base

end
--------------------------------------------------------
class Feature < ActiveRecord::Base

end
--------------------------------------------------------
class DefaultFeature < Feature

end
--------------------------------------------------------
class CustomFeature < Feature

end
-------------------------------------------------------
class PropertyFeature < ActiveRecord::Base

end

One Property can have many Features, and one Feature is associated with many
Properties. There are two kinds of Features: DefaultFeatures and
CustomFeatures, for what Im using single table inheritance. Both kinds of
Features have exactly the same fields, but i need to differentiate them in
my application. Im using a different model. Using the model PropertyFeature
is a must because it has fields i need to use.

What i want to achieve, if possible, is being able to access Features from
an Property instance like this:

property = Property.first
property.features
property.custom_features
property.default_features

And also add features to a property:

property << CustomFeature.new

I'd appreciate any help on how to do this (i've tried everything i could
think of), or maybe my approach is wrong to begin with, in which case i'd
love to hear a better way to to this.

thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,967
Messages
2,570,148
Members
46,694
Latest member
LetaCadwal

Latest Threads

Top