hzamani / active_record-acts_as

Simulate multi-table inheritance for activerecord models
MIT License
252 stars 86 forks source link

[Feature Request] Adding accepts_nested_attributes_for actable model #73

Open brunzino opened 8 years ago

brunzino commented 8 years ago

I'm building a testing tool that gets, sets parameters for active_record resources, and it gets tripped up when working with my models that use active_record-acts_as. I was a little surprised to find that the parent object does not accept nested attributes for acts_as attributes. Example below

class NightReport < ActiveRecord::Base
  acts_as :report
  # with attribute :night_supervisor 
end

class Report < ActiveRecord::Base
  actable 
  # with attribute :date 
end

$ NightReport.new( {:night_supervisor => "Nick B", :report_attributes => { :date => Date.today } )
$ ActiveRecord::UnknownAttributeError: unknown attribute: report_attributes

I understand this capability is a little strange ("In which scenario would you want to send attributes with report_attributes => {} ?" ). Tough to explain briefly, but it has to do with the fact that the night_report.attributes list does not include report.attributes.

Are there any adverse effects to adding this capability?

I'd be happy to write up the specs, submit pull request myself.

Thanks for the gem!

-Nick

EDIT: removed section about it appearing to already accept nested attributes

manuelmeurer commented 7 years ago

Hi Nick,

Does this work?

class NightReport < ActiveRecord::Base
  acts_as :report 
  accepts_nested_attributes_for :report
end