Ich bin neu bei bookshelf.js und ich versuche, eine Eins-zu-viele-Beziehung aus zwei Tabellen zu erstellen, und wenn ich die Daten vom Postboten abrufen möchte, wirft es den folgenden Fehler :Undefinierte Bindung beim Kompilieren von SELECT-Abfrage:
"Nicht definierte Bindung (n) erkannt wird, wenn SELECT-Abfrage kompiliert. customer_order_line
select * from customer_order_line
wo customer_order_line
id_order_line
in. (?)"
hier mein Datenmodell für customer_order ist:
var customer_order = db.Model.extend({
tableName: 'customer_order',
hasTimestamps: true,
orders : function() {
return this.hasMany('order_line', 'id_order_line');
},
payment : function() {
return this.belongsTo('payment','id_payment');
}
})
module.exports = db.model('customer_order', customer_order);
customer_order_line:
var order_line = db.Model.extend({
tableName: 'customer_order_line',
product : function(){
return this.belongsTo('Product','id_products');
},
order : function(){
return this.belongsTo('customer_order','id_customer_order');
}
})
module.exports = db.model('order_line', order_line);
und hier ist meine Funktion, die die Daten abruft:
getOrders: function(req, res, next) {
Customer_orders.forge()
.fetch({withRelated: ['orders']})
.then(function (collection){
res.json({
error : false,
data : collection.toJSON()
});
})
.catch(function (err){
res.status(500)
.json({
error : true,
data: {message: err.message}
});
});
}
MySQL-Tabellen:
CREATE TABLE customer_order (
id_customer_order INT AUTO_INCREMENT NOT NULL,
id_employee INT NOT NULL,
id_payment INT NOT NULL,
total DECIMAL(10,2) NOT NULL,
status NUMERIC(11) NOT NULL,
created_at TIMESTAMP NOT NULL,
updated_at TIMESTAMP NOT NULL,
PRIMARY KEY (id_customer_order)
);
CREATE TABLE customer_order_line (
id_order_line INT AUTO_INCREMENT NOT NULL,
id_customer_order INT NOT NULL,
id_products INT NOT NULL,
cost_without_taxes DECIMAL(10,2) NOT NULL,
cost_with_taxes DECIMAL(10,2) NOT NULL,
final_price DECIMAL(10,2) NOT NULL,
quantity NUMERIC(11) NOT NULL,
total_without_taxes DECIMAL(10,2) NOT NULL,
total_with_taxes DECIMAL(10,2) NOT NULL,
total DECIMAL(10,2) NOT NULL,
status NUMERIC(11) NOT NULL,
PRIMARY KEY (id_order_line)
);
danke! Meine Tabellen entsprachen nicht den Namenskonventionen von bookshelf.js, aber das Verwenden von idAttribute zum Deklarieren der ID-Spalte meiner Tabelle löste alles. –
Willkommen, wenn Sie Zweifel bezüglich ** bookshelf.js ** haben und keine Lösung dafür in der Google-Suche finden können. Gehe durch [Ghost] (https://github.com/TryGhost/Ghost), entwickelt mit bookshelf.js, wo du weitere Lösungen finden kannst. –