Fetchplan query does not return IDs in linked records

86 views
Skip to first unread message

Dário Marcelino

unread,
Nov 3, 2014, 12:40:18 PM11/3/14
to orient-...@googlegroups.com
Hi,

I've noticed that when I do a query using a fetch plan, the linked records do not contain their ID. For example, taking the demo database of 1.7.1:
select @this.toJSON('fetchPlan:roles:1') from OUser where name='admin'

Returns:
{
   
"result": [
       
{
           
"@type": "d",
           
"@rid": "#-2:1",
           
"@version": 0,
           
"this": "{\"name\":\"admin\",\"password\":\"{SHA-256}8C6976E5B5410415BDE908BD4DEE15DFB167A9C873FC4BB8A81F6F2AB448A918\",\"status\":\"ACTIVE\",\"roles\":[{\"name\":\"admin\",\"inheritedRole\":null,\"mode\":1,\"rules\":{\"database.bypassrestricted\":15}}]}"
       
}
   
],
   
"notification": "Query executed in 0.057 sec. Returned 1 record(s)"
}

which does not include the ID of the admin role (#4:0).

Is there anyway to populate the IDs of linked records?

Thanks!

Jonathan Rosen

unread,
Nov 3, 2014, 9:17:08 PM11/3/14
to orient-...@googlegroups.com
select @rid, @this.toJSON('fetchPlan:roles:1') from OUser where name='admin'

Does that work for you?

Dário Marcelino

unread,
Nov 4, 2014, 5:22:53 AM11/4/14
to orient-...@googlegroups.com
Hi Jonathan,

That does include the parent row RID (#5:0) but not the child row ID (#4:0) which is what I'm after:

{
            "@type": "d",
            "@rid": "#-2:1",
            "@version": 0,
            "rid": "#5:0",

Dário Marcelino

unread,
Nov 10, 2014, 4:16:14 PM11/10/14
to orient-...@googlegroups.com
Sorry for bumping this up but does anyone have any ideas on how to achieve this? Or OrientDB does not support returning the @rid of linked/child records in a FetchPlan? If it's the latter case I guess it would be a nice feature to have as having the @rid is useful in updates/deletions, for example.

Thanks

Jonathan Rosen

unread,
Nov 10, 2014, 4:28:29 PM11/10/14
to orient-...@googlegroups.com
What about this?

select expand(roles) from OUser where name='admin'


--

---
You received this message because you are subscribed to a topic in the Google Groups "OrientDB" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/orient-database/QPhLb5MJI6s/unsubscribe.
To unsubscribe from this group and all its topics, send an email to orient-databa...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dário Marcelino

unread,
Nov 10, 2014, 5:21:21 PM11/10/14
to
Hey Jonathan,

I appreciate the effort but I'm afraid that query only returns the roles (linked records) and not the user (parent record), result below. The objective is to get the parent and the linked records with the latter having their @rid included. My original query, select @this.toJSON('fetchPlan:roles:1') from OUser where name='admin', is very close to it but the linked records come without @rid. Let me know if this is not clear. I'm also trying to avoid running more than one query for performance reasons.

{
            "@type": "d",
            "@rid": "#4:0",
            "@version": 2,
            "@class": "ORole",
            "name": "admin",
            "inheritedRole": null,
            "mode": 1,
            "rules": {
                "database.bypassrestricted": 15
            },
            "@fieldTypes": "mode=b"
        }


Dário Marcelino

unread,
Nov 10, 2014, 5:30:01 PM11/10/14
to orient-...@googlegroups.com
After googling a bit more I ended up finding this and realised how to achieve what I was looking for. To get the rids i's just a matter of adding 'rid' to toJson(). So the solution is:
select @this.toJSON('rid,fetchPlan:roles:1') from OUser where name='admin'

{
            "@type": "d",
            "@rid": "#-2:1",
            "@version": 0,
            "this": "{\"@rid\":\"#5:0\",\"name\":\"admin\",\"password\":\"{SHA-256}8C6976E5B5410415BDE908BD4DEE15DFB167A9C873FC4BB8A81F6F2AB448A918\",\"status\":\"ACTIVE\",\"roles\":[{\"@rid\":\"#4:0\",\"name\":\"admin\",\"inheritedRole\":null,\"mode\":1,\"rules\":{\"database.bypassrestricted\":15}}]}"
        }

Which contains the RIDs.

Thanks for the help Jonathan.




On Monday, 10 November 2014 22:21:21 UTC, Dário Marcelino wrote:
Hey Jonathan,

I appreciate the effort but I'm afraid that query only returns the roles (linked records) and not the user (parent record), result below. The objective is to get the parent and the linked records with the latter having their @rid included. My original query, select @this.toJSON('fetchPlan:roles:1') from OUser where name='admin', is very close to it but the linked records come without @rid. Let me know if this is not clear. I'm also trying to avoid running more than one query for performance reasons.

{
            "@type": "d",
            "@rid": "#4:0",
            "@version": 2,
            "@class": "ORole",
            "name": "admin",
            "inheritedRole": null,
            "mode": 1,
            "rules": {
                "database.bypassrestricted": 15
            },
            "@fieldTypes": "mode=b"
        }




On Monday, 10 November 2014 21:28:29 UTC, Jonathan Rosen wrote:
Reply all
Reply to author
Forward
0 new messages