hyper-mesh icon indicating copy to clipboard operation
hyper-mesh copied to clipboard

support association proxy actions like create

Open costa opened this issue 8 years ago • 3 comments

Consider Todo belongs_to :user:

Todo.create user_id: some_user.id, ... works, but some_user.todos.create ... results in RuntimeError: Clock._create_synchromesh_scope_description_() (called class method missing)

costa avatar Dec 19 '16 21:12 costa

a has_many relationship (like todos) is represented on the client by an object of class ReactiveRecord::Collection.

I think all that has to be done, is add the create method to Collection approx like this:

def create(attrs = {}, &block)
  new_record = @target_klass.new(attrs)
  self << new_record
  new_record.save(&block)
end

catmando avatar Dec 19 '16 23:12 catmando

@catmando From the first look at it, I don't think this will suffice, unless << sets the reference attr which I doubt.

costa avatar Dec 20 '16 11:12 costa

@costa yes << does work. I'll add this into the next update

catmando avatar Dec 30 '16 20:12 catmando