diff --git a/app/services/store.coffee b/app/services/store.coffee index 02c1f94e..499b0818 100644 --- a/app/services/store.coffee +++ b/app/services/store.coffee @@ -71,9 +71,21 @@ Store = DS.Store.extend if type == 'build' && (json.repository || json.repo) data = json.repository || json.repo - if data.default_branch - data.default_branch.default_branch = true + default_branch = data.default_branch + if default_branch + default_branch.default_branch = true - @push(this.normalize('repo', data)) + last_build_id = default_branch.last_build_id + # a build is a synchronous relationship on a branch model, so we need to + # have a build record present when we put default_branch from a repository + # model into the store. We don't send last_build's payload in pusher, so + # we need to get it here, if it's not already in the store. In the future + # we may decide to make this relationship async, but I don't want to + # change the code at the moment + if build = @peekRecord('build', last_build_id) + @push(this.normalize('repo', data)) + else + @findRecord('build', last_build_id).then => + @push(this.normalize('repo', data)) `export default Store`