0

I am using ember backed by rails and postgresql. I am trying to access one model's data within a different model.

My models are like this:

App.Name = DS.Model.extend
  calc_name:    DS.attr 'string'
  calc_num:     DS.attr 'number'
  atom_list:    DS.attr 'string'
  orbital_list: DS.attr 'string'
  cluster_list: DS.attr 'string'
  bound:        DS.attr 'boolean'
  states:       DS.hasMany 'state', embedded: 'always'

App.State = DS.Model.extend
  calc_num:         DS.attr 'number'
  energy_list:      DS.attr 'string'
  dos_list:         DS.attr 'string'
  atom_subset:      DS.attr 'string'
  orbital_subset:   DS.attr 'number'
  fermi_level:      DS.attr 'number'
  core_level:       DS.attr 'number'
  elec_occ_list:    DS.attr 'string'
  elec_energy_list: DS.attr 'string'
  name:             DS.belongsTo 'name', embedded: 'always'

The variable that connects the two tables are the calc_num. So each name will have multiple states that go along with it. How can I configure it so that I can display all of the states that point to a particular name on the name template? I am using the RESTAdapter. Thank you so much and sorry for the probably easy question, I have just seen conflicting ways to approach it.

Route:

App.StateRoute = Ember.Route.extend

  model: (params) -> @store.find 'state', params.id

Abbreviated name template

article#name
      h1
        model.calc_name
        link-to 'edit' 'name.edit' model classNames='edit'
Coherent
  • 1,933
  • 5
  • 24
  • 33
  • Your embedded records is implemented using an old pattern, did you find that on stack overflow, or was it in the guides? If so could you link me to where it was? – Kingpin2k Aug 06 '14 at 03:43
  • Thanks for the help! I used this site to set it up: http://ember.vicramon.com/ The question I still have when looking at your other answer is how exactly can I specify the relationship between the two tables in terms of the particular variable that it should be trying to match up between tables. (In my case, "calc_num".) Should I be using the method used in the link you gave me or a different place? – Coherent Aug 06 '14 at 04:36

1 Answers1

0

It sounds to me like you need a joining Model, the other link (Ember-data embedded records current state?) shows you how to properly use embedded records.

App.CalcNum = DS.Model.extend
  name: DS.belongsTo('name')
  state: DS.belongsTo('state')
Community
  • 1
  • 1
Kingpin2k
  • 47,277
  • 10
  • 78
  • 96