question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't update multi link with link property

See original GitHub issue

I cannot figure out how to update multi links with link properties. Everything I try results in the error: QueryError: invalid reference to link property in top level shape.

To illustrate using an example from the docs (bottom of this page), here’s a simple schema:

type User { 
    property name -> str; 
    multi link friends -> User { 
        property nickname -> str; 
    } 
}

As the docs demonstrate, I can insert all the users and use the WITH + FOR + array_unpack statement to set multiple links and their corresponding link properties.

But now if I add another user and want to update any of the existing users’ friends list with a link and a link property, it just doesn’t happen. The following (and all permutations I could think of as far as adding and removing round brackets) does not work:

WITH U2 := User UPDATE User FILTER .name = 'Bob' 
SET { 
    friends := User.friends UNION (
        SELECT U2 { @nickname := 'new guy' } FILTER U2.name = 'John' 
    )
};  

Result: QueryError: invalid reference to link property in top level shape with the error arrow pointing to the beginning of the { @nickname … part

Note that just without the link property part I am able to add the new friend to the friends list using the query above.

I am also able to add the link with its link property if I replace all existing friends (by omitting User.friends UNION). So clearly this should be possible, but I can’t find/understand my syntax error.

Thanks for your help!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
elpranscommented, Nov 29, 2019

This looks like a bug. Your query should work. I’ll take a look soon. Also, #165 will make these sorts of queries much simpler. Meanwhile, the following workaround should work (at least in nightly):

 WITH U2 := User UPDATE User FILTER .name = 'Bob'
 SET {
     friends := (
        FOR f in {(User.friends, User.friends@nickname) 
                  UNION ((SELECT U2 FILTER .name = 'John'), 'new guy')}
        UNION f.0 {
           @nickname := f.1
        }
     )
 };
0reactions
elpranscommented, Aug 23, 2020

The += shape operator is now supported in UPDATE, so the original query can be written as:

WITH U2 := User 
UPDATE User 
FILTER .name = 'Bob'
SET {
    friends += (
        SELECT U2 {
            @nickname := 'new guy'
        } FILTER .name = 'John'
    )
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

Entity Framework doesn't seem to be able to properly link new ...
When I'm doing an update via DbSet<Xyz>.Update(xyz) , and xyz has been updated such that navigation property ( Apple ) is now a...
Read more >
How to edit Excel Links, Excel Can't update Links Error
In this video, I'm going over an example of what to do when faced with this dreaded notification in excel:'We can't update some...
Read more >
Links — Schema | EdgeDB Docs
Two GroupChat objects cannot link to the same Person ; put differently, no Person can be a member of multiple GroupChat .
Read more >
Adjusting multiple Link URLs with class - Forum | Webflow
Is there a way to assign a class (or some other way) to a link block that is repeated throughout the site, so...
Read more >
Solved: Multiple File Links in approval requests
Then when the approval returns you'll need to update all four ... You just can't add multiple files to the linked item property...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found