Skip to content

Conversation

@rcarver
Copy link
Contributor

@rcarver rcarver commented Nov 18, 2025

Tests for a few issues I've found while using @selection, fixes #232

@rcarver rcarver marked this pull request as draft November 18, 2025 15:14
assertInlineSnapshot(
of: Root.update {
$0.fields.honestCount = honestValue
//$0.fields.optionalCount = honestValue
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compile error here

) {
"""
UPDATE "roots"
SET "optionalCount" = "nestedFieldses"."optionalCount", "honestCount" = "nestedFieldses"."honestCount"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using selections table name instead of root's table name

@rcarver
Copy link
Contributor Author

rcarver commented Nov 18, 2025

@stephencelis I cannot figure out how to fix, but here are two failing tests for you.

@stephencelis stephencelis marked this pull request as ready for review December 19, 2025 19:26
Copy link
Member

@stephencelis stephencelis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking the lead on sharing failing tests. I've gone ahead and explored the issues and believe I have a workaround for one and a fix for another.

assertInlineSnapshot(
of: Root.update {
$0.fields.honestCount = honestValue
$0.fields.optionalCount = #bind(honestValue)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rcarver I'm not sure if I mentioned before, but #bind is the best way to coerce a query expression's underlying value. You could also have done Optional(honestValue) here.

While I think it's possible to add overloads to fix this. It's a pervasive problem and I'm not sure overloads are the solution...open to discuss, though!

) {
"""
UPDATE "roots"
SET "optionalCount" = "roots"."optionalCount", "honestCount" = "roots"."honestCount"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should now be fixed! Thanks for the test case!

Comment on lines +93 to +95
public struct _TableAliasName<Base: Table>: AliasName {
public static var aliasName: String { Base.tableName }
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the simplest way I could come up with to fix the nested update issue. Underscored type for now since I'm not sure folks should be using it, especially if we come up with a better way to handle things in the future. But if we come up with more use cases for this type, we could consider making a proper public API.

@stephencelis stephencelis merged commit 02734ac into pointfreeco:main Dec 22, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@Selection field name is incorrect within update

3 participants