Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $().ready ->
- window.App = {} # instances
- ### Models ###
- class window.Stop extends Backbone.RelationalModel
- url: -> @get('url')
- relations: [{
- type: Backbone.HasOne
- key: 'direction'
- relatedModel: 'Direction'
- collectionType: 'DirectionList'
- reverseRelation: {
- key: 'stops'
- }
- }]
- class window.Direction extends Backbone.RelationalModel
- url: -> @get('url')
- relations: [{
- type: Backbone.HasOne
- key: 'route'
- relatedModel: 'Route'
- collectionType: 'RouteList'
- reverseRelation: {
- key: 'directions'
- }
- }, {
- type: Backbone.HasMany
- key: 'stops'
- relatedModel: 'Stop'
- collectionType: 'StopList'
- reverseRelation: {
- key: 'direction'
- }
- }]
- class window.Route extends Backbone.RelationalModel
- url: -> @get('url')
- relations: [{
- type: Backbone.HasOne
- key: 'agency'
- relatedModel: 'Agency'
- collectionType: 'AgencyList'
- reverseRelation: {
- key: 'routes'
- }
- }, {
- type: Backbone.HasMany
- key: 'directions'
- relatedModel: Direction
- collectionType: 'DirectionList'
- reverseRelation: {
- key: 'route'
- }
- }]
- class window.Agency extends Backbone.RelationalModel
- url: -> @get('url')
- relations: [{
- type: Backbone.HasMany
- key: 'routes'
- relatedModel: Route
- collectionType: 'RouteList'
- reverseRelation: {
- key: 'agency'
- }
- }]
- class window.StopList extends Backbone.Collection
- model: Stop
- url: -> "#{@get('direction').url()}/stops"
- class window.DirectionList extends Backbone.Collection
- model: Direction
- url: -> "#{@get('route').url()}/directions"
- class window.RouteList extends Backbone.Collection
- model: Route
- url: -> "#{@get('agency').url()}/routes"
- class window.AgencyList extends Backbone.Collection
- model: Agency
- url: -> "/agencies"
- App.agencies = new AgencyList
- # setup
- App.agencies.fetch()
- a1 = App.agencies.first()
- a1.fetchRelated()
- rs = a.get('routes')
- # the issue
- a2 = rs.get('agency')
- # a2 should equal a1, but instead, a2 is undefined
- # help?
Add Comment
Please, Sign In to add comment