【问题标题】:Backbone relational - how is it possible to find related model by two foreign keys?骨干关系 - 如何通过两个外键找到相关模型?
【发布时间】:2013-08-07 15:38:08
【问题描述】:

在我的模型中,我已经定义了关系,所以它的外键属性被相关模型所取代。

我有一个想法,从数据库中放弃两个相同的值,例如 relatedIdrelated - 如果我为字段 related 定义模型关系,relatedId 值将保持不变 - 我将可以使用。

是否有可能以某种方式在模型属性的主干关系中使用 collection.where() 方法,这些属性表示相关模型(它们具有对象数据类型)?如果我定义相关的 id - 如下所示 - 它不起作用:

collection.where({
    related : 14 // this property contains related model, but not id after backbone initializes, i've also tried to use relatedId key instead - this does not work
})

我非常需要这样的方法,因为我必须通过很多属性找到模型,而且从头开始很难做到:/

能否请教一个方法?

【问题讨论】:

    标签: backbone.js backbone-relational


    【解决方案1】:

    我真的很喜欢使用数据库“视图”来有效地扁平化关系,以便更轻松地查询。效果很好。

    【讨论】:

      猜你喜欢
      • 2012-06-30
      • 1970-01-01
      • 1970-01-01
      • 2012-05-30
      • 1970-01-01
      • 1970-01-01
      • 2014-03-17
      • 2012-05-02
      • 1970-01-01
      相关资源
      最近更新 更多