Skip to content

Commit

Permalink
fix: Bilingual relational field
Browse files Browse the repository at this point in the history
  • Loading branch information
boazpoolman committed Apr 22, 2022
1 parent 9c56e64 commit ecedd29
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 8 additions & 4 deletions server/services/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ const getLanguageLinks = async (page, contentType, defaultURL, excludeDrafts) =>
const links = [];
links.push({ lang: page.locale, url: defaultURL });

const populate = ['localizations'].concat(Object.keys(strapi.contentTypes[contentType].attributes).reduce((prev, current) => {
if (strapi.contentTypes[contentType].attributes[current].type === 'relation') {
prev.push(current);
}
return prev;
}, []));

await Promise.all(page.localizations.map(async (translation) => {
const translationEntity = await strapi.query(contentType).findOne({
where: {
Expand All @@ -46,8 +53,7 @@ const getLanguageLinks = async (page, contentType, defaultURL, excludeDrafts) =>
$notNull: true,
} : {},
},
orderBy: 'id',
populate: ['localizations'],
populate,
});

if (!translationEntity) return null;
Expand Down Expand Up @@ -141,8 +147,6 @@ const createSitemapEntries = async () => {
const excludeDrafts = config.excludeDrafts && strapi.contentTypes[contentType].options.draftAndPublish;

const populate = ['localizations'].concat(Object.keys(strapi.contentTypes[contentType].attributes).reduce((prev, current) => {


if (strapi.contentTypes[contentType].attributes[current].type === 'relation') {
prev.push(current);
}
Expand Down
2 changes: 2 additions & 0 deletions server/services/pattern.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const getAllowedFields = (contentType, allowedFields = []) => {
&& field.target
&& field.relation.endsWith('ToOne') // TODO: implement `ToMany` relations (#78).
&& fieldName !== 'localizations'
&& fieldName !== 'createdBy'
&& fieldName !== 'updatedBy'
) {
const relation = strapi.contentTypes[field.target];

Expand Down

0 comments on commit ecedd29

Please sign in to comment.