diff --git a/app/models/build.coffee b/app/models/build.coffee index 336cda61..1d5d6b23 100644 --- a/app/models/build.coffee +++ b/app/models/build.coffee @@ -19,6 +19,7 @@ Build = Model.extend DurationCalculations, pullRequestTitle: DS.attr() pullRequestNumber: DS.attr('number') eventType: DS.attr('string') + repositoryId: DS.attr('number') repo: DS.belongsTo('repo', async: true) commit: DS.belongsTo('commit') diff --git a/app/models/repo.coffee b/app/models/repo.coffee index 97755916..6e35b2ff 100644 --- a/app/models/repo.coffee +++ b/app/models/repo.coffee @@ -35,7 +35,7 @@ Repo = Model.extend builds: (-> id = @get('id') builds = @store.filter('build', event_type: ['push', 'api'], repository_id: id, (b) -> - b.get('repo.id') == id && (b.get('eventType') == 'push' || b.get('eventType') == 'api') + b.get('repositoryId')+'' == id+'' && (b.get('eventType') == 'push' || b.get('eventType') == 'api') ) # TODO: move to controller @@ -52,7 +52,7 @@ Repo = Model.extend pullRequests: (-> id = @get('id') builds = @store.filter('build', event_type: 'pull_request', repository_id: id, (b) -> - b.get('repo.id') == id && b.get('eventType') == 'pull_request' + b.get('repositoryId')+'' == id+'' && b.get('eventType') == 'pull_request' ) # TODO: move to controller diff --git a/app/serializers/build.coffee b/app/serializers/build.coffee index 3212b68d..bf97457d 100644 --- a/app/serializers/build.coffee +++ b/app/serializers/build.coffee @@ -16,4 +16,23 @@ Serializer = V2FallbackSerializer.extend else @_super.apply(this, arguments) + normalize: (modelClass, resourceHash) -> + result = @_super(modelClass, resourceHash) + + data = result.data + + # for some reasone repo's promise not always has its id set + # so we can't always do build.get('repo.id') + # this ensures that repositoryId is always reachable on build + # TODO: look into the real cause of the problem (maybe it will be gone + # after fully switching to V3 and/or updating ember-data) + if repoId = resourceHash.repository_id + data.attributes.repositoryId = repoId + else if resourceHash.repository + if href = resourceHash.repository['@href'] + id = href.match(/\d+/)[0] + data.attributes.repositoryId = id + + return result + `export default Serializer`