Open
Description
I opened this issue to discuss the possible DSL ideas for the Composite Resources feature.
The feature is:
Imagine the case when in user signup form user can enter company name and the company will be automatically created:
class UserWithCompanyForm < ActiveForm::Base
self.main_model = :user
attributes :email, :password, :company_name, presence: true
def save
if @model.save
Company.create(owner_id: @model.id, name: company_name)
true
else
false
end
end
end
Instead of code above, we could provide some API.
I just need to understand the difference between this and the association
method, is this for the resources that have no relations to the main model? If so what do you imagine/suggest a good DSL to do so?
I have a very rough suggestion:
class UserWithCompanyForm < ActiveForm::Base
self.main_model = :user
attributes :email, :password, :company_name, presence: true
composite :company do
owner_id: @model.id
name: company_name
end
end
@kirs please if you have any ideas in mind lets discuss them here.
Metadata
Metadata
Assignees
Labels
No labels