Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using the same field operation multiple times does not work #1095

Closed
steebchen opened this issue Nov 8, 2023 · 0 comments · Fixed by #1094
Closed

Using the same field operation multiple times does not work #1095

steebchen opened this issue Nov 8, 2023 · 0 comments · Fixed by #1094

Comments

@steebchen
Copy link
Owner

steebchen commented Nov 8, 2023

The following does not work:

user, err := client.Post.FindUnique(
	db.Post.Or(
		db.Post.Status.Equals(PostStatusUnpublished),
		db.Post.Status.Equals(PostStatusFlagged),
	),
).Exec(ctx)

This works:

user, err := client.Post.FindUnique(
	db.Post.Or(
		db.Post.And(
			db.Post.Status.Equals(PostStatusUnpublished),
		),
		db.Post.And(
			db.Post.Status.Equals(PostStatusFlagged),
		),
	),
).Exec(ctx)

For the above example, you can consider using .In() instead:

user, err := client.Post.FindUnique(
	db.Post.In([]PostStatus{PostStatusUnpublished, PostStatusFlagged}),
).Exec(ctx)

Alternatively, wrap your queries using the same field in an .And() like above.

For linking many items, you can do the following:

user, err := client.User.FindUnique(
	User.ID.Equals("new"),
).Update(
	User.Posts.Link(
		Post.ID.Equals("a"),
		Post.ID.Equals("b"),
		Post.ID.Equals("c"),
	),
).Exec(ctx)

// or

worker, err := client.Worker.FindUnique(
	Worker.ID.Equals("new"),
).Update(
	db.Worker.Actions.Link(
		db.Action.TenantIDID(
			db.Action.TenantID.Equals(tenantId),
			db.Action.ID.Equals("action:one"),
		),
	),
	db.Worker.Actions.Link(
		db.Action.TenantIDID(
			db.Action.TenantID.Equals(tenantId),
			db.Action.ID.Equals("action:two"),
		),
	),
).Exec(ctx)

TODO @steebchen: explain why this does not work (AST reasons)

This results in unexpected behaviour. #1094 disallows the use of this and fails on runtime.

@steebchen steebchen changed the title Using OR with the same field name does not work Using same field operation multiple times does not work Nov 9, 2023
@steebchen steebchen linked a pull request Nov 9, 2023 that will close this issue
@steebchen steebchen reopened this Nov 10, 2023
@steebchen steebchen changed the title Using same field operation multiple times does not work Using the same field operation multiple times does not work Nov 10, 2023
@steebchen steebchen closed this as not planned Won't fix, can't repro, duplicate, stale Nov 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging a pull request may close this issue.

1 participant