Open chumakoff opened 2 years ago
Currently has_many relations are added to a parent record via ActiveRecord's collection<< method. And there is no way to change that.
ActiveRecord
collection<<
through
So, there should be a way to specify (and implement on API level) a custom method that appends has_many relationships.
Example
# post_resource.rb has_many :tags, create_method: :add_tag def add_tag(tag) @model.post_tags.create!(tag: tag) if @model.acceptable_tag?(tag) end
Currently has_many relations are added to a parent record via
ActiveRecord
'scollection<<
method. And there is no way to change that.collection<<
doesn't always work for complex associations (especially for usingthrough
option)collection<<
doesn't provide full control and confidencecollection<<
silently ignores invalid recordscollection<<
on model level (which is now the only workaround) for API purposes is not a good waySo, there should be a way to specify (and implement on API level) a custom method that appends has_many relationships.
Example