作者:极御云安全 | 来源:互联网 | 2023-08-29 08:36
在ecto中,使用has_manybelongs_to等关系时,会默认使用子表中的父表ID,如以下两表:1.father字段分别为id,fname2.child
在ecto中,使用has_many belongs_to等关系时,会默认使用子表中的父表ID,如以下两表:
1.father 字段分别为 id, fname
2.child 字段分别是 id, cname, father_id(默认的外键形式)
这在echo中很好理解
但如果以下情况
1.father 字段分别为 id, fname
2.child 字段分别是 id, cname [foreign key (id) references father (id)]
即:father.id 与 child.id关联, 在ecto中设置外键则抛ID已存在的错误。
这样情况在ecto中model到底该如何定义?