Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

haste
Copy link
Contributor

@haste haste commented Sep 14, 2025

This PR fixes handling of empty input in relationship name guesser. Owl.IO.input/1 returns nil when allowing optional input. It also trims the input and returns empty strings as nil.

Previously it would fail with the following stack:

Multiple foreign keys found from `MyApp.MyDomain.ComplementaryProduct` to `MyApp.MyDomain.Product` with the guessed name `product`.

Provide a relationship name for the one with the following info:

Resource: `MyApp.MyDomain.ComplementaryProduct`
Relationship Type: :belongs_to
Guessed Name: `:product`
Relationship Destination: `MyApp.MyDomain.Product`
Constraint Name: `"complementary_products_complementary_product_id_fkey"`.

Leave empty to skip adding this relationship.

Name:
> 

** (FunctionClauseError) no function clause matching in String.trim/1    
    
    The following arguments were given to String.trim/1:
    
        # 1
        nil
    
    Attempted function clauses (showing 1 out of 1):
    
        def trim(string) when is_binary(string)
    
    (elixir 1.18.1) lib/string.ex:1312: String.trim/1
    (ash_postgres 2.6.17) lib/resource_generator/spec.ex:784: AshPostgres.ResourceGenerator.Spec.name_all_relationships/6
    (elixir 1.18.1) lib/enum.ex:1276: anonymous fn/3 in Enum.flat_map/2
    (stdlib 6.1.2) maps.erl:860: :maps.fold_1/4
    (elixir 1.18.1) lib/enum.ex:2558: Enum.flat_map/2
    (ash_postgres 2.6.17) lib/resource_generator/spec.ex:661: anonymous fn/4 in AshPostgres.ResourceGenerator.Spec.do_add_relationships/3
    (elixir 1.18.1) lib/enum.ex:1714: Enum."-map/2-lists^map/1-1-"/2
    (elixir 1.18.1) lib/enum.ex:1714: Enum."-map/2-lists^map/1-1-"/2

Contributor checklist

Leave anything that you believe does not apply unchecked.

  • I accept the AI Policy, or AI was not used in the creation of this PR.
  • Bug fixes include regression tests
  • Chores
  • Documentation changes
  • Features include unit/acceptance tests
  • Refactoring
  • Update dependencies

@@ -781,14 +781,14 @@ defmodule AshPostgres.ResourceGenerator.Spec do
end

Owl.IO.input(label: label, optional: true)
|> String.trim()
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd just pipe this into Kernel.||("")

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed it to just do that. :)

Copy link
Contributor

Choose a reason for hiding this comment

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

we still need the String.trim after 😄

@haste haste force-pushed the fix-empty-input-relationship-name-guesser branch from 04ec9ee to 0a00afd Compare September 14, 2025 13:17
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.

2 participants