Skip to content

Commit

Permalink
Merge pull request #520 from bookbrainz/follow-relationship-redirect-…
Browse files Browse the repository at this point in the history
…bbid

fix(relationships): Follow BBID redirects when loading relationships aliases
  • Loading branch information
MonkeyDo committed Oct 7, 2020
2 parents 723d746 + 9ef878f commit 55ff508
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/server/helpers/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,11 @@ export function loadEntityRelationships(req: $Request, res: $Response, next: Nex
entity.relationships = relationshipSet ?
relationshipSet.related('relationships').toJSON() : [];

function getEntityWithAlias(relEntity) {
async function getEntityWithAlias(relEntity) {
const redirectBbid = await orm.func.entity.recursivelyGetRedirectBBID(orm, relEntity.bbid, null);
const model = commonUtils.getEntityModelByType(orm, relEntity.type);

return model.forge({bbid: relEntity.bbid})
return model.forge({bbid: redirectBbid})
.fetch({require: false, withRelated: ['defaultAlias'].concat(utils.getAdditionalRelations(relEntity.type))});
}

Expand Down
5 changes: 3 additions & 2 deletions src/server/routes/merge.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,11 @@ function loadEntityRelationships(entity, orm, transacting): Promise<any> {
entity.relationships = relationshipSet ?
relationshipSet.related('relationships').toJSON() : [];

function getEntityWithAlias(relEntity) {
async function getEntityWithAlias(relEntity) {
const redirectBbid = await orm.func.entity.recursivelyGetRedirectBBID(orm, relEntity.bbid, null);
const model = commonUtils.getEntityModelByType(orm, relEntity.type);

return model.forge({bbid: relEntity.bbid})
return model.forge({bbid: redirectBbid})
.fetch({withRelated: 'defaultAlias'});
}

Expand Down

0 comments on commit 55ff508

Please sign in to comment.