【问题标题】:Waterline Edges associations水线边缘关联
【发布时间】:2015-03-17 06:00:44
【问题描述】:

我刚刚准备了一个模型,它包含两个顶点和它们之间的一条边,v1、v2和e1,而v1是A类的实例或顶点,v2是B类的顶点。e1是E类的实例。我想为这种关系准备水线模式,模式如下所示:

identity:'A',
connection:'ex1',
attributes:{
  title:'string',
  r : {collection:'B', through:'E', via:'A'}
}
identity:'A',
connection:'ex1',
attributes:{
  title:'string',
  r : {collection:'A', through:'E', via:'B'}
}

如果我使用此模式映射到 orientdb 我的字段,它会将 collection:'B' 显示为 A 类中的链接集。我只想通过边缘将它们联系起来。有没有办法跳过提及集合,而只是建立一个关系,根据需要将边缘 e1 的 @rid 映射到这些类的 OUT 或 IN 字段?

【问题讨论】:

    标签: sails.js orientdb waterline sails-orientdb


    【解决方案1】:

    xeeB,你没有提到你正在使用哪个 OrientDB 的水线适配器(至少有 3 个)。我假设它是waterline-orientdb

    在您的架构示例中,您正在定义“多对多通过”关联,但您缺少(或未共享)“通过”模型的定义 (@987654322 @)。

    最后,使用边在顶点之间建立关系的最简单方法是使用"Many-to-many" associations。您可以根据自己的示例使用以下代码 sn-p 执行此操作:

    // Model A
    {
      tableName : 'A',
      identity : 'a',
      connection : 'ex1',
      attributes : {
        title : 'string',
        r : {
          collection : 'b',
          via : 'r',
          dominant : true
        }
      }
    }
    // Model B
    {
      tableName : 'B',
      identity : 'b',
      connection : 'ex1',
      attributes : {
        title : 'string',
        r : {
          collection : 'a',
          via : 'r'
        }
      }
    }
    

    完整的“多对多”关联工作示例位于: https://github.com/appscot/waterline-orientdb/blob/master/example/associations/many-to-many.js

    更新: waterline-orientdb 现在被命名为sails-orientdb。

    【讨论】:

    • 现在我的问题是使用 'populate' 我可以从 A 获取 B 类顶点的属性,例如 A.find().populate('r').exec(function(err,model ){/*代码*/});但我的要求是,如果我站在顶点 A 上,我也想获得 Edge 属性,这可以通过 waterline-orientdb 实现吗?
    • 嗨@xeeB,在waterline(sails-orientdb 只是水线的适配器)中做到这一点的方法是使用多对可能的关联,不幸的是目前还不支持( issue #705)。所以...您最好的选择是使用sails-orientdb 自定义方法.query() 并使用普通的SQL 查询。
    • 谢谢,对我很有帮助
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-15
    • 1970-01-01
    • 1970-01-01
    • 2014-10-17
    • 1970-01-01
    • 2021-04-24
    相关资源
    最近更新 更多