如何将表列与另一个表关联
所以基本上我想知道我需要什么关联来链接我的路由表和员工表。我有一个路由表,其中包含一个员工列(数组类型),其中保存员工 ID。我还有一个员工表,其中包含(名字,姓氏,电话号码)。
has_many :employees,foreign_key: :employees, class_name: :Employee
不起作用并给出错误。有什么想法吗?
给出了这个错误
ActiveRecord::StatementInvalid (PG::UndefinedColumn: ERROR: column employees.employees does not exist)
LINE 1: SELECT "employees".* FROM "employees" WHERE "employees"."emp...
So basically I like to know what association i need to link my routes table with employees table. I have a routes table with an employees column (array type) which holds employee id's. I also have an employee table that has (first_name, last_name, phone_number).
A has_many :employees, foreign_key: :employees, class_name: :Employee
does not work and gives an error. Any ideas?
This error is given
ActiveRecord::StatementInvalid (PG::UndefinedColumn: ERROR: column employees.employees does not exist)
LINE 1: SELECT "employees".* FROM "employees" WHERE "employees"."emp...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在这里使用数组列是一个坏主意:
相反,您最可能想要的是自我引用关联:
如果经理-员工关系应该是多对多,而不是使用连接表的一对多。
Using an array column here is a just bad idea:
Instead you most likely want is a self-referential assocation:
If the manager-employee relation should be many to many instead of one to many use a join table.