mirror of
https://github.com/ent/ent.git
synced 2026-05-24 09:31:56 +03:00
entc/gen: add support for referencing fks to existing fields (#1289)
This commit is contained in:
@@ -425,7 +425,8 @@ func (gq *GroupQuery) sqlAll(ctx context.Context) ([]*Group, error) {
|
||||
ids := make([]int, 0, len(nodes))
|
||||
nodeids := make(map[int][]*Group)
|
||||
for i := range nodes {
|
||||
if fk := nodes[i].group_tenant; fk != nil {
|
||||
fk := nodes[i].group_tenant
|
||||
if fk != nil {
|
||||
ids = append(ids, *fk)
|
||||
nodeids[*fk] = append(nodeids[*fk], nodes[i])
|
||||
}
|
||||
|
||||
@@ -25,9 +25,8 @@ var (
|
||||
PrimaryKey: []*schema.Column{GroupsColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "groups_tenants_tenant",
|
||||
Columns: []*schema.Column{GroupsColumns[2]},
|
||||
|
||||
Symbol: "groups_tenants_tenant",
|
||||
Columns: []*schema.Column{GroupsColumns[2]},
|
||||
RefColumns: []*schema.Column{TenantsColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
@@ -59,9 +58,8 @@ var (
|
||||
PrimaryKey: []*schema.Column{UsersColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "users_tenants_tenant",
|
||||
Columns: []*schema.Column{UsersColumns[3]},
|
||||
|
||||
Symbol: "users_tenants_tenant",
|
||||
Columns: []*schema.Column{UsersColumns[3]},
|
||||
RefColumns: []*schema.Column{TenantsColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
@@ -79,16 +77,14 @@ var (
|
||||
PrimaryKey: []*schema.Column{UserGroupsColumns[0], UserGroupsColumns[1]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "user_groups_user_id",
|
||||
Columns: []*schema.Column{UserGroupsColumns[0]},
|
||||
|
||||
Symbol: "user_groups_user_id",
|
||||
Columns: []*schema.Column{UserGroupsColumns[0]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.Cascade,
|
||||
},
|
||||
{
|
||||
Symbol: "user_groups_group_id",
|
||||
Columns: []*schema.Column{UserGroupsColumns[1]},
|
||||
|
||||
Symbol: "user_groups_group_id",
|
||||
Columns: []*schema.Column{UserGroupsColumns[1]},
|
||||
RefColumns: []*schema.Column{GroupsColumns[0]},
|
||||
OnDelete: schema.Cascade,
|
||||
},
|
||||
|
||||
@@ -425,7 +425,8 @@ func (uq *UserQuery) sqlAll(ctx context.Context) ([]*User, error) {
|
||||
ids := make([]int, 0, len(nodes))
|
||||
nodeids := make(map[int][]*User)
|
||||
for i := range nodes {
|
||||
if fk := nodes[i].user_tenant; fk != nil {
|
||||
fk := nodes[i].user_tenant
|
||||
if fk != nil {
|
||||
ids = append(ids, *fk)
|
||||
nodeids[*fk] = append(nodeids[*fk], nodes[i])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user