简体   繁体   English

找不到“ user_id” Ember-Data问题的模型

[英]No Model Found for 'user_id' Ember-Data issue

For some reason I keep getting this error when trying to create a record using ember store. 由于某些原因,当尝试使用ember store创建记录时,我一直收到此错误。

Here is the error: Uncaught Error: No model was found for 'user_id' 这是错误: Uncaught Error: No model was found for 'user_id'

Here is my actions function that causes the error. 这是导致错误的我的动作函数。 I've removed user_id and anything that uses the user model from the model as well as from the creation and it still gives me the same error. 我已经从模型以及创建中删除了user_id以及所有使用该user模型的内容,但仍然出现相同的错误。 I simply can't figure out what's causing the error, the error itself isn't very informative either. 我根本无法弄清楚是什么原因引起的错误,错误本身也不是非常有用。 It's not giving me any line numbers that are causing the error in my code. 它没有给我任何导致代码出错的行号。

addProposal: function() {
    var store = this.store;
    var self = this;

    var foundUser = function(user) {
        console.log(user);
        var proposal = store.createRecord('proposal', {
            discount_code: self.get('discount_code'),
            user_id: user,
            status_id: self.get('status_id'),
            timeline: self.get('timeline'),
            expiry_dt: self.get('expiry_dt'),
            company_name: self.get('company_name'),
            client_email: self.get('client_email'),
            proposal_needed_by: self.get('proposal_needed_by'),
            data_needed_by: self.get('data_needed_by'),
            proposal_expiry_dt: self.get('proposal_send_dt'),
            liason_id: user,
            qb_id: self.get('qb'),
            version: self.get('version'),
            custom_discount: self.get('custom_discount'),
            notes: self.get('notes'),
        });


        var onSuccess = function(proposal) {
            console.log('Proposal was created');

            this.transitionToRoute('proposal', proposal);
        };

        var onFailure = function() {
            console.log('Something went wrong');
        };

        proposal.save().then(onSuccess, onFailure);

    };

    store.find('user', $.cookie('user_id')).then(foundUser);

    //console.log(this.get('statuses'));

}

Here is my proposal model: 这是我的提案模型:

import DS from 'ember-data';
import Ember from 'ember';

var attr = DS.attr,
    hasMany = DS.hasMany,
    belongsTo = DS.belongsTo;

export default DS.Model.extend({
    discount_code: attr(),

    user_id: belongsTo('user', {async: true}),
    user: Ember.computed.alias('user_id'),


    status_id: belongsTo('status', {async: true}),
    status: Ember.computed.alias('status_id'),


    timeline: attr(),
    proposal_needed_by: attr(),
    data_needed_by: attr(),
    proposal_expiry_dt: attr(),

    company_name: attr(),
    client_name: attr(),
    client_email: attr(),
    sent_dt: attr(),

    liason_id: belongsTo('user', {async: true}),
    // Semantically better
    liason: Ember.computed.alias('liason_id'),

    qb_id: belongsTo('user', {async: true}),
    qb: Ember.computed.alias('qb_id'),

    version: attr(),
    custom_discount: attr(),
    notes: attr(),
    created_at: attr(),
    friendly_date: function() {
        return moment(this.get('created_at')).format('MMM Do YY, h:mm a');
    }.property('created_at'),


    updated_at: attr(),
    comments: hasMany('comment', {async: true}),
    logs: hasMany('log', {async: true}),
});

Most likely the server is returning a hash with key user_ids , causing ember to look for a model called user_id , whereas in your case the server should be returning the key users . 服务器很可能返回带有键user_ids的散列,从而使ember查找名为user_id的模型,而在您的情况下,服务器应返回键users

If you can't change the server you can write a custom adapter which will change the key name in the payload coming from the server. 如果您无法更改服务器,则可以编写一个自定义适配器,该适配器将更改来自服务器的有效负载中的密钥名称。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM