You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[db-macros] support for children without names in lookup_resource! (#7508)
Presently, the `lookup_resource!` macro generates code that will not
compile when a child resource has `lookup_by_name = false` in its
`lookup_resource!` macro invocation.
This is because the code for selecting a child resource by name given
the parent is generated in the `lookup_resource!` invocation for the
*parent* resource, which doesn't *know* whether the child has
`lookup_by_name = true` or `lookup_by_name = false`. This means that
this code is unconditionally generated, even when there is no name
column for the child (i.e., it is an `Asset` rather than a `Resource`).
While we currently have plenty of `lookup_resource!` invocations for
`Asset`s, none of them are currently the child of another resource.
While working on the webhook implementation, I wanted the
`WebhookSecret` resource to be a child of the `WebhookReceiver` resource
for authz purposes, but secrets do not have names. This resulted in the
`lookup_resource!` macro generating code that wouldn't compile. I've
cherry-picked this commit from that branch to try and land it
separately.
This commit fixes that issue by changing the child selector functions
from being generated by the parent's `lookup_resource!` invocation to
instead being generated by the child's `lookup_resource!` invocation.
This way, we can decide whether or not to generate the child-by-name
selectors based on whether or not the child has `lookup_by_name = true`
or not. Since all the `lookup_resource!` invocations are in the same
file, it's alright for the child's `lookup_resource!` invocation to
generate `impl` blocks for the parent as well.
Furthermore, as the list of `children` in the parent resource's
`lookup_resource!` invocation is no longer necessary, I've removed it.
Now, `lookup_resource!` invocations need only provide a list of
ancestors, and need not define their children. This is a bit nicer, as
the relationships are only defined in one place.
0 commit comments