OrientDB: Join in OrientDB - How to

1.4k views Asked by At

Hello everybody (again), I am trying to join two class in orient db. I want all the records and properties from two class as a result. Since here join not works so please suggest me in orient db how join works and please suggest me also how to use edges for join in orientdb

1

There are 1 answers

0
hartmut On

Its rather simple: Write the rid of the target-record into a field in your master-table.

I will describe using the activeorient, the ruby-orientDB ORM:

 DB.create_class :basiswert
 => Basiswert 

 DB.create_class :stock
 => Stock 

 apple = Basiswert.create name: 'Apple', kind: 'silicon valley company'
 => #<Basiswert:0x0000000241ca38 @metadata={"type"=>"d", "class"=>"basiswert", "version"=>1, "fieldTypes"=>nil, "cluster"=>53, "record"=>0}, @d=nil, @attributes={"name"=>"Apple", "kind"=>"silicon valley company", "created_at"=>Fri, 24 Feb 2017 16:55:37 +0100}> 
apple_stock =  Stock.create symbol: 'AAPL', :price => 200, basiswert: apple
 => #<Stock:0x00000003ecb370 @metadata={"type"=>"d", "class"=>"stock", "version"=>1, "fieldTypes"=>"basiswert=x", "cluster"=>57, "record"=>0}, @d=nil, @attributes={"symbol"=>"AAPL", "price"=>200, "basiswert"=>"#53:0", "created_at"=>Fri, 24 Feb 2017 16:55:43 +0100}> 
apple_stock.basiswert
 => #<Basiswert:0x0000000241ca38 @metadata={"type"=>"d", "class"=>"basiswert", "version"=>1, "fieldTypes"=>nil, "cluster"=>53, "record"=>0}, @d=nil, @attributes={"name"=>"Apple", "kind"=>"silicon valley company", "created_at"=>Fri, 24 Feb 2017 16:55:37 +0100}> 

Alternatively you just put "#53:0" into »apple-stock.basiswert«

This is a unidirectional join (or a simple link). Obviously you can query the stock-class

Stock.where basiswert: apple-stock.rid

or in plain OrientDB-SQL

select from stock where basiswert= "#53:0"