hasMany关系:包括从另一个方向

编程入门 行业动态 更新时间:2024-10-18 23:24:37
本文介绍了hasMany关系:包括从另一个方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

说我有下一个模型:

user.json: {//... "relations":{ "invoices": { "type": "hasMany", "model": "Invoice", "foreignKey": "receiverId" }, } //... }

又名用户可能有很多发票.这段代码将字段ReceiverId添加到发票模型中.

A.k.a. a user might have many invoices. This code adds the field receiverId to the invoice model.

现在,我想获取一张发票清单,包括其收货人.我该怎么办?

Now I want to get a list of invoices including their receivers. How can I do that?

Invoice.find({include: "reciever"})

Invoice.find({include: "user"})

不起作用,返回:未为发票模型定义关系\"接收器\"错误.

Did not work, returned: "Relation \"receiver\" is not defined for Invoice model" error.

感谢您的帮助.

推荐答案

您必须定义在您的帐单模型中属于属于" 关系.

invoice.json:

invoice.json:

{//... "relations":{ "receiver": { "type": "belongsTo", "model": "Receiver" }, } //... }

然后您可以像这样查询模型:

Then you can query your model like this:

Invoice.find({include: "receiver"}, function(data){ console.log(data); });

更多推荐

hasMany关系:包括从另一个方向

本文发布于:2023-10-24 20:13:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1524893.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方向   关系   hasMany

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!