Separate model to get the same resource

I have a situation where the same model Event should be sent by the backend server:

  • list of events by country (CountryEventsController hit: countries/:country_id/events)
  • list of events by shop (ShopEventsController hit: shops/:shop_id/events)

Finally, the two controllers send an array of the same model Event.

On Ember side I declared 2 models:

  • Shop
  • Event

and connected them with hasMany relations on both sides.

To fetch country events, I use Event model and to fetch Shop events, I had to create a separate model shop-event:

model() {
    return RSVP.hash({
      events:'event', { country_id: this.get('')}),
      shopEvents:'shop-event', { shop_id: this.get('') })

The questions I have:

  1. Isn’t it a duplication to declare the same model?
  2. What attributes should I put in the second model ?
  3. Finally when getting the same model type, I have to delete an Event from Shop association. How to do that to be able to call ShopEventsController? If I call shopEvent.destroyRecord(); it will call EventsController#destroy action and delete completely the Event from the database.

I defined adapters for shop-event and event, - this way I can create/edit/delete Country events and create/delete only ShopEvents by keeping Country events untouched.

The creation works:

let shopEvent ='shopEvent', {
          shop: this.currentShop.get('shop'),
          event:'event', event.get('id')),

But how to delete ?

Actually, I declared just 2 relations belongsTo in shop-event model:


export default DS.Model.extend({
  shop: DS.belongsTo(),
  event: DS.belongsTo()

but don’t think it to be correct, because it is not a join-table ShopsEvents. How to do in such a situation ? Thank you