1

我要在 OrientDB 中插入带有嵌入字段的记录,然后使用过滤器查询该记录:

insert into MyClass set embeddedField = {'@type': 'd', 'id': 1}

运作良好,并且

select from MyClass

返回我添加的记录。但是,当我为嵌入式字段添加过滤器时,我没有得到任何结果:

select from MyClass where embdeddedField = {'@type': 'd', 'id': 1}

我认为它可能会发生,因为东方将@version字段添加到嵌入文档中,所以我尝试使用版本进行搜索:

select from MyClass where embdeddedField = {'@type': 'd', '@version': 0, 'id': 1}

但仍然没有结果。

问题:知道如何按整个文档过滤嵌入字段吗?无需按嵌入文档的每个字段显式过滤:

select from MyClass
where embdeddedField.id = 1 
and embdeddedField.field2 = val2
and embeddedField.field3 = val3

因为出于多种原因,我想将整个对象作为单个查询参数传递:

select from MyClass where embdeddedField = ?
4

1 回答 1

0

那是因为提供的 Hash 被转换为嵌入式类。

也许看看 ActiveOrientWiki https://github.com/topofocus/active-orient/wiki/Relations

解释:拿一个类base,有一个具有两个属性(无模式)的文档并将现有文档添加到其中

( 0..9 ).each do | b |
    base_record= Base.create label: b, first_list: []
    ( 0..9 ).each {|c| base_record.first_list << FirstList.create( label: c ) }
 end
INFO->CREATE VERTEX base CONTENT {"label":0,"first_list":[]}
INFO->CREATE VERTEX first_list CONTENT {"label":0}
INFO->update #136:0 set first_list = first_list || [#147:0]   return after @this

然后嵌入链接,记录看起来像

 => #<Base:0x00000000041a60e0 @metadata={:type=>"d", :class=>"base", :version=>11, :fieldTypes=>"first_list=z", :cluster=>129, :record=>1},
 @attributes={:first_list=>["#149:1", "#150:1", "#151:1", "#152:1", "#145:2", "#146:2", "#147:2", "#148:2", "#149:2", "#150:2"], :label=>"1"}> 

如果展开列表项,可以查询“@type”

如果你添加一个没有删除的文档,同样的事情会发生

( 0..9 ).each {|c| base_record.first_list << FirstList.new( label: c ) }
20.04.(12:53:59) INFO->update #130:2 set first_list = first_list || [{ @type: 'd' ,@class: 'first_list' ,label: 0 }]   return after @this

INFO->CREATE VERTEX base CONTENT {"label":"c","first_list":[]}
'#130:2'.expand
 => #<Base:0x00000000043927a0 @metadata={:type=>"d", :class=>"base", :version=>11, :fieldTypes=>"first_list=z", :cluster=>130, :record=>2}, 
 @attributes={:first_list=>["#151:12", "#152:12", "#145:13", "#146:13", "#147:13", "#148:13", "#149:13", "#150:13", "#151:13", "#152:13"], :label=>"c"}>

如果省略类名,则只有 rid 的变化范围

INFO-> update #132:2 set first_list = first_list || { @type: 'd'  ,label: 0 }   return after @this
 => [#<Base:0x0000000003a26fb8 @metadata={:type=>"d", :class=>"base", :version=>3, :fieldTypes=>"first_list=z", :cluster=>132, :record=>2}, 
@attributes={:first_list=>["#3:0"], :label=>"d"}>] 

无论如何,查询@type失败

于 2019-04-19T09:54:55.000 回答