gpt4 book ai didi

javascript - 未找到 'user_id' Ember-Data 问题的模型

转载 作者:行者123 更新时间:2023-12-02 17:08:39 25 4
gpt4 key购买 nike

由于某种原因,我在尝试使用 ember 存储创建记录时不断收到此错误。

错误如下:未捕获错误:未找到“user_id”的模型

这是我导致错误的操作函数。我已经从模型和创建中删除了 user_id 以及任何使用 user 模型的内容,但它仍然给我同样的错误。我根本无法弄清楚是什么导致了错误,错误本身也没有提供太多信息。它没有给我任何导致代码错误的行号。

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'));

}

这是我的提案模型:

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}),
});

最佳答案

很可能服务器返回带有 key user_ids 的哈希值,导致 ember 查找名为 user_id 的模型,而在您的情况下,服务器应该返回 key 用户

如果您无法更改服务器,您可以编写一个自定义适配器,它将更改来自服务器的有效负载中的键名称。

关于javascript - 未找到 'user_id' Ember-Data 问题的模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25020222/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com