Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STI subclasses with lifecycle creators do not work #189

Open
stevemadere opened this issue Sep 17, 2016 · 2 comments
Open

STI subclasses with lifecycle creators do not work #189

stevemadere opened this issue Sep 17, 2016 · 2 comments

Comments

@stevemadere
Copy link

stevemadere commented Sep 17, 2016

If ParentClass in a STI scheme has a lifecycle,
ChildClass cannot define functional lifecycle
creators.

If ChildClass attempts to define a lifecycle, it simply
end up extending the lifecycle of ParentClass.

This is mostly a problem if the ChildClass tries to define
any lifecycle create actions. If ChildClass contains code like
this:

lifecycle do
   state :child_specific_state
   create :child_specific_creator, become: child_specific_state
end

Then ParentClass gets a new creator called child_specific_creator.

When the lifecycle create action is executed, on ChildClass the
ChildClass::Lifecycle method returns the same value as ParentClass::Lifecycle.

Unfortunately, the lifecycle object itself contains a pointer to the
model.

If you have a look at the source code for the Hobo::Models::Lifecycle::Creator#run!
method, you will see it call lifecycle.model.new for any creator action and thus
only creates instances of ParentClass even if the creator called was child_specific_creator.

@stevemadere stevemadere changed the title STI subclasses with lifecycles do not work STI subclasses with lifecycle creators do not work Sep 17, 2016
@stevemadere
Copy link
Author

I am having to work around this by just not using a lifecycle creator when creating an instance of ChildClass. I am using ordinary rails create and the auto-generated hobo controller new/create actions handle my UI.

However, if my use case had involved multiple distinct creators in ChildClass, it would be much uglier.

@stevemadere
Copy link
Author

It is even worse than I thought.
Auto routes for ChildClass are completely FUBAR by the lifecycle
in ParentClass.

Even with a directive like this

  auto_actions except: :lifecycle

in the definition of ChildClassesController, all of the
ParentClassController lifecycle actions get a route under /child_classes/
and NONE of the standard CRUD actions get a route:

It does exactly the opposite of what I requested.

Fun.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant