hzamani / acts_as_relation

Multi table Inheritance for rails
http://hzamani.github.com/acts_as_relation/
MIT License
180 stars 58 forks source link

Rails 3.2 - .specific is not working? #55

Closed RuiPedroLeal closed 10 years ago

RuiPedroLeal commented 10 years ago

Upfront, I'm using ruby 1.9.3 and rails 3.2.15. Also, using the '~>0.1' modifier on my gemfile.

Have 2 simple models:

class Person < ActiveRecord::Base
  belongs_to :country
  belongs_to :affiliation, :class_name => "Entity"

  attr_accessible :active, :email, :name, :personizable_id, :personizable_type, :phone, :shortcv, :url  
  acts_as_superclass
end

class Member < ActiveRecord::Base
  belongs_to :position
  belongs_to :function
  attr_accessible :alias, :bibtext_name, :cv, :order, :photo, :sname, :state

  acts_as :person, :as => :personizable
end

The person migration includes:

    create_table :people do |t|
      t.integer :personizable_id
      t.string :personizable_type
    end

From the rails console i'm able to do:

m = Member.first
m.name (an attrib from Person)

But can't do:

p = Person.first
p.specific (returns nil)

The specific db entry has the correct ID and personizable_type as 'Member'

Any help please?

RuiPedroLeal commented 10 years ago

Sorry everyone, but after some digging on the code (and a coffee) i've managed to understand what was missing:

acts_as_superclass :as => :personizable

Probably could help someone.

Regards!