Hey guys, I had a question. I have a one to many r...
# orm-help
b
Hey guys, I had a question. I have a one to many relationship in my schema. An owner can have many dogs, but a dog can have only one owner. Schema:
Copy code
type Owner {
  id: ID! @unique
  dogs: [Dog!]!
}

type Dog {
  id: ID! @unique
  name: String!
  owner: Owner
}
But whenever I try to do the query of
Copy code
query {
  dog (where: {id: "1"}) {
    owner
  }
}
it wants me to have a where input for the owner. Why is this the case? I know dogs can only have one owner... I just want to receive the information of that one owner.
k
You need to use relation tags.
Copy code
type Owner {
  id: ID! @unique
  dogs: [Dog!]! @relation(name: "UserToDog")
}

type Dog {
  id: ID! @unique
  name: String!
  owner: Owner @relation(name: "UserToDog")
}
Make that change and re-deploy prisma and it should work as you expected it to.
b
Yea I ended up figuring that out! was going to point that out!
👍 1
k
Suppose if I felt like a jerk I coulda just RTFM'd you, haha!
b
I initially thought the reason why it wasn't showing up was because i forgot to do owner: Owner! since I wasn't requiring it.
k
Nope, wasn't that. But it is an option - you could totally make an owner-less dog if you so desired it for your project.
b
The dog is just a reference to what I'm actually doing 😛
realistically it wouldn't exist without an owner.