ember.js - How can I set different data on the same model in ember data? -


in app there 2 models: app.company , app.contract. company has many contracts. i'm using ember data.

i want display companies have contracts start in given month. example, /jan-2013 show companies have contracts starting in january of 2013. want display relevant contracts.

so, have month resource:

app.router.map(function() {   this.resource('month', { path: '/:month_id' }); }); 

each company , contract have id. question is, what's best way go setting controllers?

currently i'm returning necessary data server each month. example, april 2013 return

{     month: {         id: "apr-2013",         company_ids: [5, 23, 905, 4, 59]     },      companies: [         {             id: 5,             name: "acme, inc.",             contract_ids: [94, 84, 20, 1]         },         ...     ],      contracts: [         {             id: 94,             date: "2013-04-02",             new_monthly_fee: 50182         },         ...     ] } 

if structure things standard way, run problem. company @ id 5 shows in both april 2013 , may 2013. company has different array of contract_ids in 2 months. if first visit april, when visit may ember retrieve thinks same data store; won't updated contracts.

i can think of 2 ways solve this:

  1. in setupcontroller hook in monthroute, set content on contractscontroller.

  2. remove ids on both companies , contracts, , send them embedded: always in json payload.

what correct/idiomatic way accomplish this?

how can set different data on same model in ember data?

you cant set different data on same model, in ember or other mvc framework.

what correct/idiomatic way accomplish this?

when run kind of issue sign need step , consider modeling domain in different way.

when think of ember model means exists server-side not have way. in case you've got month model not need exist on server, it's way of representing date range. server-side models company , contract. instead of querying server month , sideloading company/contract data, more idiomatic query company or contract directly, possibly including query parameters server returns relevant contracts , associated companies.

now user moves around app can expect on time or of companies , contracts going in memory. in fact might decide load them when app boots. in case, query use restrict gets loaded via api not going have showing right companies via ui. needs done client side via filter.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -