STI with many to many association

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!

Rodrigo P. wrote in post #977397:

Hello!

Im using ruby 1.9.2 and Rails 3.0.3.

This is the Ruby (programming language) list. There are separate
resources for Rails (the web framework which happens to be written in
Ruby).

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs