Last active
August 29, 2015 13:58
-
-
Save JFickel/9977235 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
attr = DS.attr; | |
Gameway.User = DS.Model.extend({ | |
name: attr('string'), | |
email: attr('string'), | |
lolAccount: DS.belongsTo('lolAccount'), | |
avatarUrl: attr('string'), | |
teams: DS.hasMany('team', { async: true }) | |
}) | |
Gameway.Team = DS.Model.extend({ | |
name: attr('string'), | |
lolRegion: attr('string'), | |
user: DS.belongsTo('user') | |
}) | |
Gameway.LolAccount = DS.Model.extend({ | |
userId: DS.belongsTo('user'), | |
summonerId: attr('number'), | |
summonerName: attr('string'), | |
soloTier: attr('string'), | |
soloRank: attr('string'), | |
region: attr('string') | |
}) | |
// Ruby converted to json from server: | |
{:lol_accounts=> | |
[{:id=>1, | |
:user_id=>1, | |
:summoner_id=>22136211, | |
:summoner_name=>"test summoner", | |
:solo_tier=>"PLATINUM", | |
:solo_rank=>"II", | |
:region=>"na"}], | |
:teams=> | |
[{:id=>1, :name=>"Cloud 9", :lol_region=>"na", :user_id=>1}, | |
{:id=>2, :name=>"SK Telecom", :lol_region=>"na", :user_id=>1}, | |
{:id=>3, :name=>"Fnatic", :lol_region=>"na", :user_id=>1}, | |
{:id=>4, :name=>"Alliance", :lol_region=>"na", :user_id=>1}, | |
{:id=>5, :name=>"Royal Club", :lol_region=>"na", :user_id=>1}], | |
:user=> | |
{:id=>1, | |
:name=>"jfickel", | |
:email=>"[email protected]", | |
:avatar_url=> | |
"https://s3.amazonaws.com/gameway-production/user_accounts/default_profile.png", | |
:lol_account=>1, | |
:teams=>[1, 2, 3, 4, 5]} | |
} | |
// Assume var data is this hash converted to json | |
this.store.pushPayload('user', data) | |
this.store.getById('user', 1).get('lolAccount') | |
=> undefined | |
this.store.getById('user', 1).get('teams.0') | |
=> undefined | |
this.store.getById('user', 1)._data | |
=> | |
{ avatarUrl: "https://s3.amazonaws.com/gameway-production/user_accounts/default_profile.png" | |
email: "[email protected]" | |
id: 1 | |
lolAccount: undefined | |
lol_account: 1 | |
name: "jfickel" | |
teams: undefined } | |
this.store.getById('lolAccount', 1)._data | |
{ id: 1 | |
region: "na" | |
soloRank: "II" | |
soloTier: "PLATINUM" | |
summonerId: 22136211 | |
summonerName: "test summoner" | |
userId: undefined | |
user_id: 1 } | |
this.store.getById('team', 1)._data | |
=> | |
{ id: 1 | |
lolRegion: "na" | |
name: "You Gotta Be Kiddin Me" | |
user: Class(the user model) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment