mirror of
https://github.com/ent/ent.git
synced 2026-05-28 09:49:08 +03:00
entc/gen: add support for referencing fks to existing fields (#1289)
This commit is contained in:
@@ -419,7 +419,8 @@ func (cq *CardQuery) sqlAll(ctx context.Context) ([]*Card, error) {
|
||||
ids := make([]int, 0, len(nodes))
|
||||
nodeids := make(map[int][]*Card)
|
||||
for i := range nodes {
|
||||
if fk := nodes[i].user_card; fk != nil {
|
||||
fk := nodes[i].user_card
|
||||
if fk != nil {
|
||||
ids = append(ids, *fk)
|
||||
nodeids[*fk] = append(nodeids[*fk], nodes[i])
|
||||
}
|
||||
|
||||
@@ -456,7 +456,8 @@ func (fq *FileQuery) sqlAll(ctx context.Context) ([]*File, error) {
|
||||
ids := make([]int, 0, len(nodes))
|
||||
nodeids := make(map[int][]*File)
|
||||
for i := range nodes {
|
||||
if fk := nodes[i].user_files; fk != nil {
|
||||
fk := nodes[i].user_files
|
||||
if fk != nil {
|
||||
ids = append(ids, *fk)
|
||||
nodeids[*fk] = append(nodeids[*fk], nodes[i])
|
||||
}
|
||||
@@ -481,7 +482,8 @@ func (fq *FileQuery) sqlAll(ctx context.Context) ([]*File, error) {
|
||||
ids := make([]int, 0, len(nodes))
|
||||
nodeids := make(map[int][]*File)
|
||||
for i := range nodes {
|
||||
if fk := nodes[i].file_type_files; fk != nil {
|
||||
fk := nodes[i].file_type_files
|
||||
if fk != nil {
|
||||
ids = append(ids, *fk)
|
||||
nodeids[*fk] = append(nodeids[*fk], nodes[i])
|
||||
}
|
||||
|
||||
@@ -614,7 +614,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_info; fk != nil {
|
||||
fk := nodes[i].group_info
|
||||
if fk != nil {
|
||||
ids = append(ids, *fk)
|
||||
nodeids[*fk] = append(nodeids[*fk], nodes[i])
|
||||
}
|
||||
|
||||
@@ -29,9 +29,8 @@ var (
|
||||
PrimaryKey: []*schema.Column{CardsColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "cards_users_card",
|
||||
Columns: []*schema.Column{CardsColumns[6]},
|
||||
|
||||
Symbol: "cards_users_card",
|
||||
Columns: []*schema.Column{CardsColumns[6]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
@@ -129,9 +128,8 @@ var (
|
||||
PrimaryKey: []*schema.Column{FieldTypesColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "field_types_files_field",
|
||||
Columns: []*schema.Column{FieldTypesColumns[50]},
|
||||
|
||||
Symbol: "field_types_files_field",
|
||||
Columns: []*schema.Column{FieldTypesColumns[50]},
|
||||
RefColumns: []*schema.Column{FilesColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
@@ -156,23 +154,20 @@ var (
|
||||
PrimaryKey: []*schema.Column{FilesColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "files_file_types_files",
|
||||
Columns: []*schema.Column{FilesColumns[6]},
|
||||
|
||||
Symbol: "files_file_types_files",
|
||||
Columns: []*schema.Column{FilesColumns[6]},
|
||||
RefColumns: []*schema.Column{FileTypesColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
{
|
||||
Symbol: "files_groups_files",
|
||||
Columns: []*schema.Column{FilesColumns[7]},
|
||||
|
||||
Symbol: "files_groups_files",
|
||||
Columns: []*schema.Column{FilesColumns[7]},
|
||||
RefColumns: []*schema.Column{GroupsColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
{
|
||||
Symbol: "files_users_files",
|
||||
Columns: []*schema.Column{FilesColumns[8]},
|
||||
|
||||
Symbol: "files_users_files",
|
||||
Columns: []*schema.Column{FilesColumns[8]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
@@ -247,9 +242,8 @@ var (
|
||||
PrimaryKey: []*schema.Column{GroupsColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "groups_group_infos_info",
|
||||
Columns: []*schema.Column{GroupsColumns[6]},
|
||||
|
||||
Symbol: "groups_group_infos_info",
|
||||
Columns: []*schema.Column{GroupsColumns[6]},
|
||||
RefColumns: []*schema.Column{GroupInfosColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
@@ -292,9 +286,8 @@ var (
|
||||
PrimaryKey: []*schema.Column{NodesColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "nodes_nodes_next",
|
||||
Columns: []*schema.Column{NodesColumns[2]},
|
||||
|
||||
Symbol: "nodes_nodes_next",
|
||||
Columns: []*schema.Column{NodesColumns[2]},
|
||||
RefColumns: []*schema.Column{NodesColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
@@ -315,16 +308,14 @@ var (
|
||||
PrimaryKey: []*schema.Column{PetsColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "pets_users_pets",
|
||||
Columns: []*schema.Column{PetsColumns[3]},
|
||||
|
||||
Symbol: "pets_users_pets",
|
||||
Columns: []*schema.Column{PetsColumns[3]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
{
|
||||
Symbol: "pets_users_team",
|
||||
Columns: []*schema.Column{PetsColumns[4]},
|
||||
|
||||
Symbol: "pets_users_team",
|
||||
Columns: []*schema.Column{PetsColumns[4]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
@@ -384,23 +375,20 @@ var (
|
||||
PrimaryKey: []*schema.Column{UsersColumns[0]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "users_groups_blocked",
|
||||
Columns: []*schema.Column{UsersColumns[11]},
|
||||
|
||||
Symbol: "users_groups_blocked",
|
||||
Columns: []*schema.Column{UsersColumns[11]},
|
||||
RefColumns: []*schema.Column{GroupsColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
{
|
||||
Symbol: "users_users_spouse",
|
||||
Columns: []*schema.Column{UsersColumns[12]},
|
||||
|
||||
Symbol: "users_users_spouse",
|
||||
Columns: []*schema.Column{UsersColumns[12]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
{
|
||||
Symbol: "users_users_parent",
|
||||
Columns: []*schema.Column{UsersColumns[13]},
|
||||
|
||||
Symbol: "users_users_parent",
|
||||
Columns: []*schema.Column{UsersColumns[13]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.SetNull,
|
||||
},
|
||||
@@ -418,16 +406,14 @@ var (
|
||||
PrimaryKey: []*schema.Column{SpecCardColumns[0], SpecCardColumns[1]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "spec_card_spec_id",
|
||||
Columns: []*schema.Column{SpecCardColumns[0]},
|
||||
|
||||
Symbol: "spec_card_spec_id",
|
||||
Columns: []*schema.Column{SpecCardColumns[0]},
|
||||
RefColumns: []*schema.Column{SpecsColumns[0]},
|
||||
OnDelete: schema.Cascade,
|
||||
},
|
||||
{
|
||||
Symbol: "spec_card_card_id",
|
||||
Columns: []*schema.Column{SpecCardColumns[1]},
|
||||
|
||||
Symbol: "spec_card_card_id",
|
||||
Columns: []*schema.Column{SpecCardColumns[1]},
|
||||
RefColumns: []*schema.Column{CardsColumns[0]},
|
||||
OnDelete: schema.Cascade,
|
||||
},
|
||||
@@ -445,16 +431,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,
|
||||
},
|
||||
@@ -472,16 +456,14 @@ var (
|
||||
PrimaryKey: []*schema.Column{UserFriendsColumns[0], UserFriendsColumns[1]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "user_friends_user_id",
|
||||
Columns: []*schema.Column{UserFriendsColumns[0]},
|
||||
|
||||
Symbol: "user_friends_user_id",
|
||||
Columns: []*schema.Column{UserFriendsColumns[0]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.Cascade,
|
||||
},
|
||||
{
|
||||
Symbol: "user_friends_friend_id",
|
||||
Columns: []*schema.Column{UserFriendsColumns[1]},
|
||||
|
||||
Symbol: "user_friends_friend_id",
|
||||
Columns: []*schema.Column{UserFriendsColumns[1]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.Cascade,
|
||||
},
|
||||
@@ -499,16 +481,14 @@ var (
|
||||
PrimaryKey: []*schema.Column{UserFollowingColumns[0], UserFollowingColumns[1]},
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "user_following_user_id",
|
||||
Columns: []*schema.Column{UserFollowingColumns[0]},
|
||||
|
||||
Symbol: "user_following_user_id",
|
||||
Columns: []*schema.Column{UserFollowingColumns[0]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.Cascade,
|
||||
},
|
||||
{
|
||||
Symbol: "user_following_follower_id",
|
||||
Columns: []*schema.Column{UserFollowingColumns[1]},
|
||||
|
||||
Symbol: "user_following_follower_id",
|
||||
Columns: []*schema.Column{UserFollowingColumns[1]},
|
||||
RefColumns: []*schema.Column{UsersColumns[0]},
|
||||
OnDelete: schema.Cascade,
|
||||
},
|
||||
|
||||
@@ -417,7 +417,8 @@ func (nq *NodeQuery) sqlAll(ctx context.Context) ([]*Node, error) {
|
||||
ids := make([]int, 0, len(nodes))
|
||||
nodeids := make(map[int][]*Node)
|
||||
for i := range nodes {
|
||||
if fk := nodes[i].node_next; fk != nil {
|
||||
fk := nodes[i].node_next
|
||||
if fk != nil {
|
||||
ids = append(ids, *fk)
|
||||
nodeids[*fk] = append(nodeids[*fk], nodes[i])
|
||||
}
|
||||
|
||||
@@ -417,7 +417,8 @@ func (pq *PetQuery) sqlAll(ctx context.Context) ([]*Pet, error) {
|
||||
ids := make([]int, 0, len(nodes))
|
||||
nodeids := make(map[int][]*Pet)
|
||||
for i := range nodes {
|
||||
if fk := nodes[i].user_team; fk != nil {
|
||||
fk := nodes[i].user_team
|
||||
if fk != nil {
|
||||
ids = append(ids, *fk)
|
||||
nodeids[*fk] = append(nodeids[*fk], nodes[i])
|
||||
}
|
||||
@@ -442,7 +443,8 @@ func (pq *PetQuery) sqlAll(ctx context.Context) ([]*Pet, error) {
|
||||
ids := make([]int, 0, len(nodes))
|
||||
nodeids := make(map[int][]*Pet)
|
||||
for i := range nodes {
|
||||
if fk := nodes[i].user_pets; fk != nil {
|
||||
fk := nodes[i].user_pets
|
||||
if fk != nil {
|
||||
ids = append(ids, *fk)
|
||||
nodeids[*fk] = append(nodeids[*fk], nodes[i])
|
||||
}
|
||||
|
||||
@@ -1115,7 +1115,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_spouse; fk != nil {
|
||||
fk := nodes[i].user_spouse
|
||||
if fk != nil {
|
||||
ids = append(ids, *fk)
|
||||
nodeids[*fk] = append(nodeids[*fk], nodes[i])
|
||||
}
|
||||
@@ -1169,7 +1170,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_parent; fk != nil {
|
||||
fk := nodes[i].user_parent
|
||||
if fk != nil {
|
||||
ids = append(ids, *fk)
|
||||
nodeids[*fk] = append(nodeids[*fk], nodes[i])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user