Skip to content

Commit

Permalink
feat: set correct association with references
Browse files Browse the repository at this point in the history
  • Loading branch information
dpilch committed Mar 6, 2024
1 parent df65382 commit 587feb7
Show file tree
Hide file tree
Showing 7 changed files with 430 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2494,6 +2494,363 @@ exports[`Primary key info within a belongsTo model tests should generate correct
}"
`;

exports[`custom references sets the association to the references field for hasMany/belongsTo 1`] = `
"{
\\"version\\": 1,
\\"models\\": {
\\"SqlPrimary\\": {
\\"name\\": \\"SqlPrimary\\",
\\"fields\\": {
\\"id\\": {
\\"name\\": \\"id\\",
\\"isArray\\": false,
\\"type\\": \\"Int\\",
\\"isRequired\\": true,
\\"attributes\\": []
},
\\"content\\": {
\\"name\\": \\"content\\",
\\"isArray\\": false,
\\"type\\": \\"String\\",
\\"isRequired\\": false,
\\"attributes\\": []
},
\\"related\\": {
\\"name\\": \\"related\\",
\\"isArray\\": true,
\\"type\\": {
\\"model\\": \\"SqlRelated\\"
},
\\"isRequired\\": true,
\\"attributes\\": [],
\\"isArrayNullable\\": true,
\\"association\\": {
\\"connectionType\\": \\"HAS_MANY\\",
\\"associatedWith\\": [
\\"primaryId\\"
]
}
},
\\"createdAt\\": {
\\"name\\": \\"createdAt\\",
\\"isArray\\": false,
\\"type\\": \\"AWSDateTime\\",
\\"isRequired\\": false,
\\"attributes\\": [],
\\"isReadOnly\\": true
},
\\"updatedAt\\": {
\\"name\\": \\"updatedAt\\",
\\"isArray\\": false,
\\"type\\": \\"AWSDateTime\\",
\\"isRequired\\": false,
\\"attributes\\": [],
\\"isReadOnly\\": true
}
},
\\"syncable\\": true,
\\"pluralName\\": \\"SqlPrimaries\\",
\\"attributes\\": [
{
\\"type\\": \\"refersTo\\",
\\"properties\\": {
\\"name\\": \\"sql_primary\\"
}
},
{
\\"type\\": \\"model\\",
\\"properties\\": {}
},
{
\\"type\\": \\"key\\",
\\"properties\\": {
\\"fields\\": [
\\"id\\"
]
}
}
],
\\"primaryKeyInfo\\": {
\\"isCustomPrimaryKey\\": false,
\\"primaryKeyFieldName\\": \\"id\\",
\\"sortKeyFieldNames\\": []
}
},
\\"SqlRelated\\": {
\\"name\\": \\"SqlRelated\\",
\\"fields\\": {
\\"id\\": {
\\"name\\": \\"id\\",
\\"isArray\\": false,
\\"type\\": \\"Int\\",
\\"isRequired\\": true,
\\"attributes\\": []
},
\\"content\\": {
\\"name\\": \\"content\\",
\\"isArray\\": false,
\\"type\\": \\"String\\",
\\"isRequired\\": false,
\\"attributes\\": []
},
\\"primary\\": {
\\"name\\": \\"primary\\",
\\"isArray\\": false,
\\"type\\": {
\\"model\\": \\"SqlPrimary\\"
},
\\"isRequired\\": false,
\\"attributes\\": [],
\\"association\\": {
\\"connectionType\\": \\"BELONGS_TO\\",
\\"targetNames\\": [
\\"primaryId\\"
]
}
},
\\"createdAt\\": {
\\"name\\": \\"createdAt\\",
\\"isArray\\": false,
\\"type\\": \\"AWSDateTime\\",
\\"isRequired\\": false,
\\"attributes\\": [],
\\"isReadOnly\\": true
},
\\"updatedAt\\": {
\\"name\\": \\"updatedAt\\",
\\"isArray\\": false,
\\"type\\": \\"AWSDateTime\\",
\\"isRequired\\": false,
\\"attributes\\": [],
\\"isReadOnly\\": true
}
},
\\"syncable\\": true,
\\"pluralName\\": \\"SqlRelateds\\",
\\"attributes\\": [
{
\\"type\\": \\"refersTo\\",
\\"properties\\": {
\\"name\\": \\"sql_related\\"
}
},
{
\\"type\\": \\"model\\",
\\"properties\\": {}
},
{
\\"type\\": \\"key\\",
\\"properties\\": {
\\"fields\\": [
\\"id\\"
]
}
},
{
\\"type\\": \\"key\\",
\\"properties\\": {
\\"name\\": \\"primary_id\\",
\\"fields\\": [
\\"primaryId\\"
]
}
}
],
\\"primaryKeyInfo\\": {
\\"isCustomPrimaryKey\\": false,
\\"primaryKeyFieldName\\": \\"id\\",
\\"sortKeyFieldNames\\": []
}
}
},
\\"enums\\": {},
\\"nonModels\\": {}
}"
`;

exports[`custom references sets the association to the references field for hasOne/belongsTo 1`] = `
"{
\\"version\\": 1,
\\"models\\": {
\\"SqlPrimary\\": {
\\"name\\": \\"SqlPrimary\\",
\\"fields\\": {
\\"id\\": {
\\"name\\": \\"id\\",
\\"isArray\\": false,
\\"type\\": \\"Int\\",
\\"isRequired\\": true,
\\"attributes\\": []
},
\\"content\\": {
\\"name\\": \\"content\\",
\\"isArray\\": false,
\\"type\\": \\"String\\",
\\"isRequired\\": false,
\\"attributes\\": []
},
\\"related\\": {
\\"name\\": \\"related\\",
\\"isArray\\": false,
\\"type\\": {
\\"model\\": \\"SqlRelated\\"
},
\\"isRequired\\": false,
\\"attributes\\": [],
\\"association\\": {
\\"connectionType\\": \\"HAS_ONE\\",
\\"associatedWith\\": [
\\"primaryId\\"
],
\\"targetNames\\": [
\\"primaryId\\"
]
}
},
\\"createdAt\\": {
\\"name\\": \\"createdAt\\",
\\"isArray\\": false,
\\"type\\": \\"AWSDateTime\\",
\\"isRequired\\": false,
\\"attributes\\": [],
\\"isReadOnly\\": true
},
\\"updatedAt\\": {
\\"name\\": \\"updatedAt\\",
\\"isArray\\": false,
\\"type\\": \\"AWSDateTime\\",
\\"isRequired\\": false,
\\"attributes\\": [],
\\"isReadOnly\\": true
},
\\"primaryId\\": {
\\"name\\": \\"primaryId\\",
\\"isArray\\": false,
\\"type\\": \\"ID\\",
\\"isRequired\\": false,
\\"attributes\\": []
}
},
\\"syncable\\": true,
\\"pluralName\\": \\"SqlPrimaries\\",
\\"attributes\\": [
{
\\"type\\": \\"refersTo\\",
\\"properties\\": {
\\"name\\": \\"sql_primary\\"
}
},
{
\\"type\\": \\"model\\",
\\"properties\\": {}
},
{
\\"type\\": \\"key\\",
\\"properties\\": {
\\"fields\\": [
\\"id\\"
]
}
}
],
\\"primaryKeyInfo\\": {
\\"isCustomPrimaryKey\\": false,
\\"primaryKeyFieldName\\": \\"id\\",
\\"sortKeyFieldNames\\": []
}
},
\\"SqlRelated\\": {
\\"name\\": \\"SqlRelated\\",
\\"fields\\": {
\\"id\\": {
\\"name\\": \\"id\\",
\\"isArray\\": false,
\\"type\\": \\"Int\\",
\\"isRequired\\": true,
\\"attributes\\": []
},
\\"content\\": {
\\"name\\": \\"content\\",
\\"isArray\\": false,
\\"type\\": \\"String\\",
\\"isRequired\\": false,
\\"attributes\\": []
},
\\"primary\\": {
\\"name\\": \\"primary\\",
\\"isArray\\": false,
\\"type\\": {
\\"model\\": \\"SqlPrimary\\"
},
\\"isRequired\\": false,
\\"attributes\\": [],
\\"association\\": {
\\"connectionType\\": \\"BELONGS_TO\\",
\\"targetNames\\": [
\\"primaryId\\"
]
}
},
\\"createdAt\\": {
\\"name\\": \\"createdAt\\",
\\"isArray\\": false,
\\"type\\": \\"AWSDateTime\\",
\\"isRequired\\": false,
\\"attributes\\": [],
\\"isReadOnly\\": true
},
\\"updatedAt\\": {
\\"name\\": \\"updatedAt\\",
\\"isArray\\": false,
\\"type\\": \\"AWSDateTime\\",
\\"isRequired\\": false,
\\"attributes\\": [],
\\"isReadOnly\\": true
}
},
\\"syncable\\": true,
\\"pluralName\\": \\"SqlRelateds\\",
\\"attributes\\": [
{
\\"type\\": \\"refersTo\\",
\\"properties\\": {
\\"name\\": \\"sql_related\\"
}
},
{
\\"type\\": \\"model\\",
\\"properties\\": {}
},
{
\\"type\\": \\"key\\",
\\"properties\\": {
\\"fields\\": [
\\"id\\"
]
}
},
{
\\"type\\": \\"key\\",
\\"properties\\": {
\\"name\\": \\"primary_id\\",
\\"fields\\": [
\\"primaryId\\"
]
}
}
],
\\"primaryKeyInfo\\": {
\\"isCustomPrimaryKey\\": false,
\\"primaryKeyFieldName\\": \\"id\\",
\\"sortKeyFieldNames\\": []
}
}
},
\\"enums\\": {},
\\"nonModels\\": {}
}"
`;

exports[`schemas with pk on a belongsTo fk works for v1 1`] = `
"{
\\"version\\": 1,
Expand Down
Loading

0 comments on commit 587feb7

Please sign in to comment.