hzamani / acts_as_relation

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

When generating a superclass object, ensure backlinks are made #67

Closed lowjoel closed 10 years ago

lowjoel commented 10 years ago

This is a case which can happen when there is a 1:many relationship between some other model and the superclass. You will have to use the #superclass message to obtain the superclass instance. However, there is no reverse relationship. So when the relationship from the superclass object is persisted, the derived object is not, because the relationship is one-way.

Example (using sample app, derived from my own code base)

store = Store.new
pen = Pen.new
store.products << pen.producible
store.save

The Producible bit of the Pen will be saved, but the Pen itself will not.

coveralls commented 10 years ago

Coverage Status

Coverage increased (+0.08%) when pulling 0f8cd355cfa10e8425e11409634b27c112f5fa61 on lowjoel:lowjoel-fix-superclass-save into 476e02ef86a10ce4cfc741ba3b0725e4b184644a on hzamani:master.

hzamani commented 10 years ago

What is the problem here?

lowjoel commented 10 years ago

I'll try to get you a repro. No time to give a more detailed explanation at the moment.

hzamani commented 10 years ago

Thanks

On Thu, Jul 17, 2014 at 2:35 AM, Joel Low notifications@github.com wrote:

I'll try to get you a repro. No time to give a more detailed explanation at the moment.

— Reply to this email directly or view it on GitHub https://github.com/hzamani/acts_as_relation/pull/67#issuecomment-49234140 .

lowjoel commented 10 years ago

@hzamani I think this might not be needed any more since we now set the inverse_of in the has_one relation we inject into the subclass. Let me merge master and try again.

lowjoel commented 10 years ago

I think it's working after placing in inverse_of. When I remove inverse_of I get this behaviour.