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

Proxied models dont have associated many to many relationship access #1379

Open
TomsOverBaghdad opened this issue Dec 16, 2022 · 0 comments
Open
Labels

Comments

@TomsOverBaghdad
Copy link
Contributor

This issue is loosely related to #319 to provide further support for proxy models

  • What is the current behavior?

Currently, django models that are a proxy of another model don't include their many to many relationships that you get by default without proxy

So if my models.py looks like this

# models.py

from django.db import models

class Publication(models.Model):
    ...

class SciencePublication(Publication):
    class Meta:
        proxy = True

class Article(models.Model):
    publications = models.ManyToManyField(
        Publication, 
        related_name="articles"
    )

and my graphene types in types.py

# types.py

import graphene_django
from .models import (
    Publication as PublicationModel, 
    SciencePublication as SciencePublicationModel
)

class Publication(graphene_django.DjangoObjectType):
    class Meta:
        model = PublicationModel

class SciencePublication(graphene_django.DjangoObjectType):
    class Meta:
        model = SciencePublicationModel

When attempting to access the articles relationship through the publication type in the graphql query I can only access it via the Publication graphql type but not through the SciencePublication type

this is fine...

query {
  getPublications() {
    articles {
      id
    }
  }
}

this is errors

query {
  getSciencePublications() {
    articles { <<<< cannot query field "articles" on type "SciencePublication"
      id
    }
  }
}
  • What is the expected behavior?

many to many relationships persist with proxy models so that this query doesn't error

query {
  getSciencePublications() {
    articles { # no errors, just smiles :)
      id
    }
  }
}
  • Please tell us about your environment:

    • Version: 3.0.0b7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant