How to set a relationship for this scenario?


#1

Hello,
I’ve been working on a project to get familiar with GraphQL and Prima. As for now, I’m using the sample database on prima.

The project is a finance app where you can manage your finance. This is a sample of my datamodel.

type Wallet {
    id: ID! @unique
    name: String!
    balance: Float! @default(value: "0.0")
    user: User!
}

type Income {
    id: ID! @unique
    name: String
    createdOn: DateTime!
    value: Float!
    wallet: Wallet!
    category: Category!
    isSettled: Boolean! @default(value: "true")
}

type Expense {
    id: ID! @unique
    name: String
    createdOn: DateTime!
    value: Float!
    wallet: Wallet!
    category: Category!
    isSettled: Boolean! @default(value: "true")
}

Here at the moment, I’m tagging an income or expense with a Wallet. But I need the ability to make the transfers between wallets. So, for that, I’m thinking about adding fromWallet: Wallet to Income type and toWallet: Wallet to type Expense.The above code is working so far. Howerver when I add the mentioned properties to the types and run prisma deploy I’m getting below error

Errors:

  Income
    ✖ The relation field `wallet` must specify a `@relation` directive: `@relation(name: "MyRelation")`
    ✖ The relation field `fromWallet` must specify a `@relation` directive: `@relation(name: "MyRelation")`

  Expense
    ✖ The relation field `wallet` must specify a `@relation` directive: `@relation(name: "MyRelation")`
    ✖ The relation field `toWallet` must specify a `@relation` directive: `@relation(name: "MyRelation")`

How can I fix this ? Any help would be appreciated.

Thanks


#2

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.