Went through the tutorial for heroes and it all makes sense, one thing that 
I'm struggling with his how to mimic the relationship between models 
especially when we roll out the backend API

E.g. Heroes may be apart of one or more guilds 

In the Database you'd have a hero table, guild table and a hero_guilds 
table with a hero id and guild id to represent the relationship.

How do you model that to Angular? Would below make sense?

export class Hero {
  id: number;
  name: string;
}

export class Group {
  id: number;
  name: string;
}

export class HeroGroups {
hero: Hero;
group: Group
}

If the above DOES make sense I'm then a bit stumped on how I'd be able to 
list in a group details a list of heroes that belonged to it or alternately 
on a hero detail view a list of groups that the hero belonged to. The Hero 
service shows a basic query of getting a hero based on the heroes id

getHero(id: number): Promise<Hero> {
  return this.getHeroes()
            .then(heroes => heroes.find(hero => hero.id === id));
}


How would I pull in Heroes groups? Would I import in it like we did Heroes?

import { HERO-GROUPS } from './mock-heroe-groups';
getHeroGroups(hero: Hero): Promise<Hero> {
     return this.getGroups()
            .then(groups => heroe-groups.find(herogroup => hero === hero));
  }
        }

-- 
You received this message because you are subscribed to the Google Groups 
"Angular" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to