Quantcast
Channel: Ember.JS - Latest topics
Viewing all articles
Browse latest Browse all 4827

How to save many-to-many relations

$
0
0

@belgoros wrote:

I have 2 models with a many-to-many relations:

  • Shop
  • Event

Being on templates/events/index.hbs page that displays the list of events, how is possible to assign an event to a shop (I have the instance of the current shop everywhere in the application via a service current-shop) ?

My first idea was to create an end-point on the backend side (`Rails’)

POST /shops/:shop_id/events/:id(.:format) v1/shop_events#handle_event

The difficulty I have on Ember side is how to call the above route from controllers/events/index.js controller ?

I tried to do as follows:

handleEvent(event) {
  let event = this.store.peekRecord('event', 1);
  let shop = this.store.peekRecord('shop', 1);
  shop.get('events').pushObject(event);
  shop.save();
}

but, of course Ember tried to hit PATCH http://localhost:3000/shops/:shop_id.

I’m using ember-data-url-templates and override adapters when needed. How to solve that without modifying the existing shop adapter ?

Thank you.

Posts: 3

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 4827

Trending Articles