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

many to many extra not working #84

Open
isaacfink opened this issue Mar 31, 2022 · 2 comments
Open

many to many extra not working #84

isaacfink opened this issue Mar 31, 2022 · 2 comments

Comments

@isaacfink
Copy link

isaacfink commented Mar 31, 2022

Hi I have these models

class package(models.Model):
    items = models.ManyToManyField('product.item', verbose_name=_("Items"), related_name="package_items")

class item(models.Model):
    products = models.ManyToManyField('product.product', verbose_name=_("Products"), null=True, blank=True)

class product(models.Model):
    options = models.ManyToManyField("product.option", verbose_name=_("Product options"), null=True, blank=True)

and this is my mutation for package and item

class create_package(DjangoCreateMutation):
    class Meta:
        model = package
        many_to_many_extras = {
            'items': {
                'add':{'type': 'CreateitemInput'}
            }
        }

class create_item(DjangoCreateMutation):
    class Meta:
        model = item
        many_to_many_extras = {
            'products': {
                'add':{'type': 'CreateproductInput'}
            }
        }

class create_product(DjangoCreateMutation):
    class Meta:
        model = product
        many_to_many_extras = {
            'options': {
                'add':{'type': 'CreateoptionInput'}
            }
        }

And when I run a mutation like this:

mutation{
  createPackage(
    input:{
      name:"random"
      description:"boring"
      sideBarText:"sample"
      items:[
        1
      ]
      itemsAdd:[
        {
          name:"bla bla bla"
          displayName:"kdjhb"
          products:[
            "cHJvZHVjdF90eXBlOjE="
          ]
          productsAdd:[
            {
              name:"product bla"
              description:"double trouble"
              price:"99.99"
            }
          ]
        }
      ]
    }
  ){
    package{
      name
      items{
        edges{
          node{
            name
            products{
              edges{
                node{
                  name
                  price
                }
              }
            }
          }
        }
      }
    }
  }
}

I only get the added product returned, why isn't the other product being added?

@isaacfink
Copy link
Author

Is there any update on this?

@NwawelAIroume
Copy link

Hi I have these models

class package(models.Model):
    items = models.ManyToManyField('product.item', verbose_name=_("Items"), related_name="package_items")

class item(models.Model):
    products = models.ManyToManyField('product.product', verbose_name=_("Products"), null=True, blank=True)

class product(models.Model):
    options = models.ManyToManyField("product.option", verbose_name=_("Product options"), null=True, blank=True)

and this is my mutation for package and item

class create_package(DjangoCreateMutation):
    class Meta:
        model = package
        many_to_many_extras = {
            'items': {
                'add':{'type': 'CreateitemInput'}
            }
        }

class create_item(DjangoCreateMutation):
    class Meta:
        model = item
        many_to_many_extras = {
            'products': {
                'add':{'type': 'CreateproductInput'}
            }
        }

class create_product(DjangoCreateMutation):
    class Meta:
        model = product
        many_to_many_extras = {
            'options': {
                'add':{'type': 'CreateoptionInput'}
            }
        }

And when I run a mutation like this:

mutation{
  createPackage(
    input:{
      name:"random"
      description:"boring"
      sideBarText:"sample"
      items:[
        1
      ]
      itemsAdd:[
        {
          name:"bla bla bla"
          displayName:"kdjhb"
          products:[
            "cHJvZHVjdF90eXBlOjE="
          ]
          productsAdd:[
            {
              name:"product bla"
              description:"double trouble"
              price:"99.99"
            }
          ]
        }
      ]
    }
  ){
    package{
      name
      items{
        edges{
          node{
            name
            products{
              edges{
                node{
                  name
                  price
                }
              }
            }
          }
        }
      }
    }
  }
}

I only get the added product returned, why isn't the other product being added?

many-to-many is working on my side
Please can you highlight or point out which item is added and which ones are not added?

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

No branches or pull requests

2 participants