简体   繁体   English

has_one / belongs_to无法加载

[英]has_one / belongs_to not loading

I think it's because of how my Proposal model is set up but I'm not sure how to get around it. 我认为这是因为我的提案模型是如何建立的,但我不确定如何解决它。

JSON Response JSON回应

{
  "proposal":[
    {
      "id":1,
      "proposee_id":1,
      "proposer_id":4
    }
  ],
  "user":{
    "id":4,
    "username":"rawr",
    "email":"rawr@ar.com",
    "proposal_id":1
  }
}

proposal model (Ember) 提案模型(Ember)

App.Proposal = DS.Model.extend
    proposer: DS.belongsTo "user"
    proposee: DS.belongsTo "user"
    status: DS.attr "string"

Proposal Model (Rails) 投标模型(路轨)

class Proposal < ActiveRecord::Base
    belongs_to :proposer, class_name: "User"
    belongs_to :proposee, class_name: "User"
end

User model (Ember) 用户模型(Ember)

App.User = DS.Model.extend
  username: DS.attr 'string'
  email: DS.attr 'string'
  password: DS.attr 'string'
  password_confirmation: DS.attr 'string'
  proposal: DS.belongsTo "proposal"

User model (Rails - truncated) 用户模型(Rails-被截断)

class User < ActiveRecord::Base
    before_save :encrypt_password

    attr_accessor :password

    has_one :proposal_to, class_name: "Proposal", foreign_key: "proposer_id"
    has_one :proposal_from, class_name: "Proposal", foreign_key: "proposee_id"
end

I figured out why. 我弄清楚了原因。
I had to change proposal_id in the JSON response to proposal . 我必须在JSON响应proposal_id中更改proposal
The change was made in Ember-Data 1.0.0Beta and is addressed here 所做的更改是在Ember-Data 1.0.0Beta中进行的,并在此处解决

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Backbone belongs_to has_many - Backbone belongs_to has_many 在视图中调用belongs_to关系 - Call belongs_to relationship in a view 在knockout.js中创建has_one类型关系 - Creating a has_one type relationship in knockout.js 将多个数据添加到 Has Many 中的一个实体并属于关系 - Adding multiple data to one entity in Has Many and belongs to relationship 如何使用Selectize.js查找或创建rails belongs_to关联? - How to use Selectize.js to find or create a rails belongs_to association? 一个模型(用户)如何只有一个其他模型(例如工作场所),但是该工作场所在Sequelize.js中属于许多用户? - How can a model (user) has only one other model (eg workplace), but the workplace belongs to many users in Sequelize.js? 检查查询结果是否属于一个实例 - Check if the result of the query belongs to one instance 表达和排序:渴望加载属于许多协会的挂起应用程序 - Express and sequelize: eager loading belongs to many associations hangs application Ember数据属于并加载另一个控制器模型记录 - Ember Data Belongs to and Loading another controller model record 检查元素是否具有某个 class 并且属于包含某个值的表单 - Check if element has a certain class and belongs to a form that contains a certain value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM