[BUG?] Missing relationships in createMany

I’m just in the middle of trying to build a createMany function, to create ~10k rows. (1k at a time)

However, I need to connect them to existing rows in a different table… My relationship fields is not showing up in the API explorer and I get an error trying to createMany with a relationship.

"Field \"stock\" is not defined by type StockPricingHistoryCreateManyInput.",

This kind of puts a stopper to things :frowning:

Are there any plans to add this? (soon-ish?)

Also would really like to know what the status on updateMany and deleteMany are. I’ll need those as well for this project.

1 Like

I can confirm, tableCreateMany() doesn’t work with connect(), and does not return items.

This works fine (tableA, tableB):

mutation {
  tableACreate(data: {
    title: "bar"
    refB: {
      connect: {
        index: 0
      }
    }
  }) {
    id
    title
  }
}

This does not work, saying Field refB is not defined. Also, it doesn’t return items, only count.

mutation {
  tableACreateMany(data: [{
    title: "foo"
    refB: {
      connect: {
        index: 0
      }
    }
  }]) {
    count
  }
}
2 Likes

@MarkLyck @mike_ekim1024 this is known issue. I will check how soon we could implement it with backend team and let you know.

3 Likes

@ilya.8base any updates on the status of createMany with relationships?

@MarkLyck we are going to start on this soon and it could take a month or so.I couldn’t tell you more now.

@ilya.8base Ouch… That’s a very long time to fix this :weary:

But thanks for the update! I guess I’ll have to write a second function for all of aliased createMany’s to manually update all records to add the relationships :disappointed_relieved:

I don’t think I can wait thaaat long for this feature to work…

@MarkLyck please do so. We know this feature is important and we are trying to do our best to finish that soon.

1 Like

@ilya.8base @sebastian.scholl since this won’t be functional in time for our prod push.

Do you recommend I add a second function to update all the records I just created using aliases to attach the relationship.

Or regress my createMany functions to be individual aliases with a single create instead? :frowning:

Hey @MarkLyck! Yeah sorry about this timeline :frowning:

If it were me, I’d move to aliases with single create operations so that I could then handle the relationships at the same time. Have two fns feels like it could potentially lead to too many API calls.

1 Like

Hi, @MarkLyck!
If I understand correctly, you want to call createMany in one graphql request, then call update mutation for each received record. But it will lead to too many API calls as regress createMany to a single call.

What kind of relations do you use in this case? If you use one to many, you could reduce the number of update calls. You could assembly all the ids from the one side for each id from the many sides and call update mutation for the table with many side. It will help to reduce the number of API calls.
For example, you have two tables authors and posts. Post has one author, Author has many posts.

  1. createMany (3 posts) -> [id1 id2 id3]
  2. update target author with received post’s ids.
mutation {
 authorUpdate(data:{
   id: "author_id"
    post:{
      connect:[
        { id:"post_id_1" }
        { id:"post_id_2" }
        { id:"post_id_3" }
      ]
    }
  }){
    id
    name
  }
}

Please, let me know what do you think about it.

1 Like

@eugene.antonevich thanks for the help!

Unfortunately in most of my tables (pretty much all of them I’m using createMany and waiting for deleteMany)

it’s a 1 to 1 relationship. Not one to many.

@sebastian.scholl also I realized given the way that the alias method to bundle mutations work… That would be a pain in case one of the relationships fail. It would not continue to create the rest of the records.

It seems like my best bet is to create an additional Trigger.after on create for all of my tables to attach the relationship one by one :frowning:

Or I have to fetch the entire table I want to attach relationships to, so I can check beforehand if the record I’m attempting to attach exists before dynamically generating a request with 1000’s of aliases.

This is a sticky situation. I would probably have this same problem with createMany actually :thinking: