Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing model relations when two different one-to-many entity relationships use the same field names #443

Open
Lezek123 opened this issue Jul 1, 2021 · 2 comments

Comments

@Lezek123
Copy link
Contributor

Lezek123 commented Jul 1, 2021

Version: 3.1.0-alpha.0

Minimal schema example:

type ForumThread @entity {
  id: ID!
  title: String!
  posts: [ForumPost!] @derivedFrom(field: "thread")
}

type ForumPost @entity {
  id: ID!
  thread: ForumThread!
}

type ProposalDiscussionThread @entity {
  id: ID!
  test: String!
  posts: [ProposalDiscussionPost!] @derivedFrom(field: "thread")
}

type ProposalDiscussionPost @entity {
  id: ID!
  thread: ProposalDiscussionThread!
  text: String!
}

Hydra codegen result:

Only the ForumThread -> ForumPost relationship is preserved in the generated models, while the ProposalDiscussionThread -> ProposalDiscussionPost relationship is missing:

proposal-discussion-post.model.ts

import { BaseModel, Model, StringField } from 'warthog';

@Model({ api: {} })
export class ProposalDiscussionPost extends BaseModel {
  @StringField({})
  text!: string;

  constructor(init?: Partial<ProposalDiscussionPost>) {
    super();
    Object.assign(this, init);
  }
}

proposal-discussion-thread.model.ts

import { BaseModel, Model, StringField } from 'warthog';

@Model({ api: {} })
export class ProposalDiscussionThread extends BaseModel {
  @StringField({})
  test!: string;

  constructor(init?: Partial<ProposalDiscussionThread>) {
    super();
    Object.assign(this, init);
  }
}

Additional observations

Changing any of the relationship field names (posts -> discussionPosts or thread -> discussionThread) in ProposalDiscussionThread -> ProposalDiscussionPost relationship resolves the issue.

@Lezek123 Lezek123 changed the title Missing model relations when two different one-to-many entity relationships have the same field names Missing model relations when two different one-to-many entity relationships use the same field names Jul 1, 2021
Lezek123 added a commit to Lezek123/substrate-runtime-joystream that referenced this issue Jul 1, 2021
@ondratra ondratra self-assigned this Jul 1, 2021
@dmtrjsg
Copy link

dmtrjsg commented May 18, 2022

Needs refreshing and allocation to the right pipeline @ondratra

@dmtrjsg
Copy link

dmtrjsg commented Aug 17, 2022

Key:
Changing any of the relationship field names (posts -> discussionPosts or thread -> discussionThread) in ProposalDiscussionThread -> ProposalDiscussionPost relationship resolves the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants