makandra / active_type

Make any Ruby object quack like ActiveRecord
MIT License
1.09k stars 74 forks source link

Support .build for nests_many / nests_one #71

Closed kdiogenes closed 3 years ago

kdiogenes commented 7 years ago

ActiveRecord adds 16 methods when we declare a has_many relationship (http://guides.rubyonrails.org/v4.2/association_basics.html#has-many-association-reference).

I would love to have build added by nests_many. I'm trying to figure out how this can be implemented, but in the meantime, an orientation would make me very happy ;-)

dmitry commented 5 years ago

@kdiogenes what was the usecase for that feature?

triskweline commented 5 years ago

I believe it would be useful to populate a nested form with some blank rows to type into.

dmitry commented 5 years ago

@triskweline at the moment I believe it is possible to do the following:

post = Post.new(items_attributes: [{}, {}])

Isn't that enough for such use case?

triskweline commented 5 years ago

There are other ways to do this, I agree! It would be nice syntactic sugar though, and since ActiveType is generally trying to get feature parity with plain ActiveRecord, it would go well with the spirit of this gem.

dmitry commented 5 years ago

@triskweline then an Array needs to be converted (for the nests_many) to Collection, and once it will be done, it could be used to fill with the methods used in activerecordsCollectionAssociation`.

FLeinzi commented 3 years ago

I will close this issue for now, because there were no activity for a long time.

If you still wish this feature in ActiveType you're welcome to open a Pull Request including green tests. Then we will discuss about it again.