Sails 1.0无法访问自动生成的关联实体路线 [英] Sails 1.0 cannot access autogenerated associated entity routes

查看:94
本文介绍了Sails 1.0无法访问自动生成的关联实体路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在客户"和预算"之间有如下关联:

I have an association between Client and Budget as follows:

//Client.js
module.exports = {
  primaryKey: 'id',

  attributes: {
    id: {
      type: 'number',
      unique: true,
      autoIncrement: true
    },
    name: {
      type: 'string'
    },
    phone: {
      type: 'string',
      unique: true
    },
    email: {
      type: 'string',
      unique: true
    },
    budgets: {
      collection: 'budget',
      via: 'client'
    },
  }
};


// Budget.js
module.exports = {
  primaryKey: 'id',

  attributes: {
    id: {
      type: 'number',
      unique: true,
      autoIncrement: true
    },
    client: {
      model: 'client'
    },
    budgetItems: {
      type: 'json'
    }
  }
};

因此,POST对这两个实体均有效,因此我可以创建它们两个,但是:

So, POST is working for both entities so I can create both of them, but:

 GET /budget/1

返回预算和关联客户的ID.

returns the budget and the id of the associated client.

 GET /budget/1/client

不填充就返回客户端ID(如我在文档(应填充).

returns the client id without populating(as i've seen in documentation it should be populated).

 GET /client/1

返回客户属性,并且没有与预算相关的字段.

returns the client attributes and there is not a field related with budgets.

 GET /client/1/budgets

返回404未找到

我正在关注此和官方文档

那我可能会想念什么?

我只是生成一个方向关联,并且已经与官方文档和第三方示例进行了比较,我的代码看起来还不错.

Is just generating one direction associations, and I've compared with official documentation and third party examples and my code looks fine.

提前谢谢!

更新:

我仍在寻找麻烦,如果我使用--silly选项进行航行,则表明存在以下路线:

I still looking for troubles and if I run sails with --silly option it shows there is the following route available:

绑定路线::获取/client/:parentid/budgets政策:本地化
绑定路径::获取/client/:parentid/budgets策略:isauth
绑定路线::获取/client/:parentid/budgets BLUEPRINT:填充

Binding route :: get /client/:parentid/budgets POLICY: localize
Binding route :: get /client/:parentid/budgets POLICY: isauth
Binding route :: get /client/:parentid/budgets BLUEPRINT: populate

但是如果我尝试访问则会返回404 Not Found,并且控制台显示以下错误,该错误是由Sails核心代码中的populate.js抛出的:

but if I try to access returns a 404 Not Found and console shows the following error, thrown by populate.js from Sails core code:

verbo:在populate蓝图操作中:指定的父记录(1) 没有budgets.

verbo: In populate blueprint action: Specified parent record (1) does not have a budgets.

Update2:

使用Sails控制台进行调试我已经看到正确生成了关联.在给定Client.findOne({id: 1}).populate('budgets').then((client)=>{console.log(client)})的情况下,打印客户端属性和关联的预算,但在以下情况下仍返回404 Not Found:GET /client/1/budgets

Debugging with sails console I've seen the association is generated properly. Given Client.findOne({id: 1}).populate('budgets').then((client)=>{console.log(client)}) print the client attributes and the associated Budgets but still return 404 Not Found when: GET /client/1/budgets

推荐答案

感谢SailsJS小组发现问题,它与第三方软件包有关,只需要从我的项目中删除它即可. sails-hook-deep-orm的所有者被警告.希望有人遇到同样的问题.

thanks to SailsJS team we've found the problem and it was related with a third party package and just had to remove it from my project. It was sails-hook-deep-orm who's owner has been warned. I hope someone with the same issue will reach this post.

还是谢谢你!

该问题可用

这篇关于Sails 1.0无法访问自动生成的关联实体路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆