Skip to content

Commit

Permalink
Correctly add fields to models (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
colodenn authored Jan 20, 2025
1 parent a1ac9fe commit 6dfc69a
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 19 deletions.
Binary file modified bun.lockb
Binary file not shown.
9 changes: 1 addition & 8 deletions src/utils/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,7 @@ export const createFields = (
const diff: Array<string> = [];

for (const fieldToAdd of fields) {
const { ...field } = fieldToAdd;

const fieldValue = {
...field,
model: { slug: modelSlug },
};

diff.push(createFieldQuery(modelSlug, fieldValue));
diff.push(createFieldQuery(modelSlug, fieldToAdd));
}

return diff;
Expand Down
10 changes: 0 additions & 10 deletions src/utils/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,6 @@ export const createModelQuery = (
* ```
*/
export const createFieldQuery = (modelSlug: string, field: ModelField): string => {
if (field.type === 'link') {
const fieldWithFlatTarget = field.target
? {
...field,
target: field.target,
}
: field;
return `alter.model('${modelSlug}').create.field(${JSON.stringify(fieldWithFlatTarget)})`;
}

return `alter.model('${modelSlug}').create.field(${JSON.stringify(field)})`;
};

Expand Down
2 changes: 1 addition & 1 deletion tests/utils/field.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ describe('fields', () => {
const diff = await diffFields(localFields, remoteFields, 'account', [], []);
expect(diff).toHaveLength(1);
expect(diff).toStrictEqual([
'alter.model(\'account\').create.field({"type":"string","slug":"name","model":{"slug":"account"}})',
'alter.model(\'account\').create.field({"type":"string","slug":"name"})',
]);
});

Expand Down

0 comments on commit 6dfc69a

Please sign in to comment.