Skip to content

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

Open
@TomsOverBaghdad

Description

@TomsOverBaghdad

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions