AVK
AVK

Reputation: 645

How to query a neighbor vertex, which has certain attributes?

Im using OrientDB 2.0. The query is simple, but I cant seem to figure it out. I have 2 classes: User and UserGroup. To make it simple, User has only username and password properties and UserGroup has only one id property. Relationship is simple:

User --- user_group --> UserGroup

where user_group is a class nam of edges connecting User and UserGroup vertices.

What I would like is to do is get a user with certain username and password where UserGroup.id is equal to group1

What I have so far is:

select expand(in('user_group')[username='foo' and password='bar']) 
from UserGroup
where id = 'group1'

But that does not work for me. What am I doing wrong?

Upvotes: 0

Views: 204

Answers (3)

Sunny
Sunny

Reputation: 127

select 
from (
     select expand(in('user_group')) 
     from UserGroup 
     where id = 'group1'
) 
where username='foo' and password='bar'

Upvotes: 0

vitorenesduarte
vitorenesduarte

Reputation: 1579

create class User extends V
create property User.username string
create property User.password string

create class UserGroup extends V
create property UserGroup.id string

create class user_group extends E


create vertex User set username = 'foo', password = 'bar'
create vertex UserGroup set id = 'group1'

create edge user_group from (select from User where username = 'foo') to (select from UserGroup where id = 'group1')


select expand(in('user_group')[username='foo'][password='bar']) 
from UserGroup
where id = 'group1'

Upvotes: 2

AVK
AVK

Reputation: 645

I think, after a couple of tries, I found the answer:

select from 
   (select expand(in('user_group'))
    from UserGroup
    where id = 'group1')
where username='foo' and password='bar'

If anyone can suggest a more elegant solution, that would be nice too

Upvotes: 0

Related Questions