-
Notifications
You must be signed in to change notification settings - Fork 142
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
Better support for interactions that wrap another interaction or model. #245
Comments
Pulling validation information off of a model is basically impossible so whatever we do we'll have to send the values to the underlying model/interaction, run the validation, and merge the results back into the wrapping interaction. |
A thought I had recently is that it might be good to just create two new |
How would that look? class CreateThing < ActiveInteraction::Base
# ...
def execute
new_model(Thing, inputs) # ?
end
end |
Yup, something like that. |
For some reason I feel weird about adding helper methods for ActiveRecord specifically. ActiveInteraciton doesn't rely on ActiveRecord, only ActiveModel. A more general solution may be to pass an optional method parameter to I think it might help to see what you'd have to do to create a new record spelled out, before we try to compress it into a helper method. class CreateThing < ActiveInteraction::Base
# ...
def execute
thing = Thing.new(inputs)
errors.merge!(thing) unless thing.save
thing
end
end This assumes that the interaction inputs map one-to-one to the record's attributes. And that the record does not use protected attributes ( |
Right, the fact that this is a common pattern and we can provide an error mapping feature makes it worth consideration in my mind. |
Currently
Would it make sense to allow setting those things when calling # new_model
compose(Thing, inputs, run: :new, check: :save, return: :itself) Heck, it could even take a proc. |
I could get on board with that. |
|
Goal
Reduce redundancy in interactions that wrap an underlying interaction or model. Often these are used in form objects and/or replace the CUD operations.
Areas of Redundancy
The text was updated successfully, but these errors were encountered: