aws-amplify / amplify-swift

A declarative library for application development using cloud services.
Apache License 2.0
448 stars 195 forks source link

Gen2 Swift Codegen for one-to-one does not compile #3735

Closed lawmicha closed 2 months ago

lawmicha commented 4 months ago

The example in https://docs.amplify.aws/swift/build-a-backend/data/data-modeling/relationships/#model-a-one-to-one-relationship

I've moved it over for testing in our integration tests as:

// Gen2_4 - Model a "one-to-one" relationship
    // https://docs.amplify.aws/swift/build-a-backend/data/data-modeling/relationships/#model-a-one-to-one-relationship
    Cart4: a.model({
        items: a.string().required().array(),
        // 1. Create reference field
        customerId: a.id(),
        // 2. Create relationship field with the reference field
        customer: a.belongsTo('Customer4', 'customerId'),
    }),
    Customer4: a.model({
        name: a.string(),
        // 3. Create relationship field with the reference field
        //    from the Cart model
        activeCart: a.hasOne('Cart4', 'customerId')
    }),

Customer4 schema has

.hasOne(customer4.activeCart, is: .optional, ofType: Cart4.self, associatedFields: [Cart4.keys.customer]),

hasOne associatedFields doesn't exist. I think we might be able to easily add it. do we need to add targetName as well? Those methods are defined over in https://github.com/aws-amplify/amplify-swift/blob/main/Amplify/Categories/DataStore/Model/Internal/Schema/ModelSchema%2BDefinition.swift#L232-L306

In the integration tests, i manually modified it to

.hasOne(customer4.activeCart, is: .optional, ofType: Cart4.self, associatedWith: Cart4.keys.customer),

Originally posted by @lawmicha in https://github.com/aws-amplify/amplify-swift/issues/3699#issuecomment-2112918336

github-actions[bot] commented 4 months ago

This issue was opened by a maintainer of this repository; updates will be posted here. If you are also experiencing this issue, please comment here with any relevant information so that we're aware and can prioritize accordingly.

lawmicha commented 4 months ago

Pending https://github.com/aws-amplify/amplify-swift/pull/3700/files

harsh62 commented 2 months ago

The fix has been released.

github-actions[bot] commented 2 months ago

This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.