Skip to content

Conversation

@matt-savvy
Copy link
Contributor

Description

Recently found that this ash.gen.resource will let you create something with an invalid relationship.

Example

mix ash.gen.resource MyApp.Blog.Post \
    -r belongs-to:author:MyApp.Accounts.User,has_any:comments:MyApp.Blog.Comment

This has two problems:

  • belongs-to (kebab-case) instead of belongs_to (snake_case)
  • has_any instead of has_many

I would expect this to fail so I can fix the typos, but instead it creates a resource with a relationships block that looks like this:

       relationships do
         belongs - to(:author, MyApp.Accounts.User)
         has_any(:comments, MyApp.Blog.Comment)
       end

Changes

  • Update Ash.Gen.Resource, add valid_relationship_type/1 and call in add_relationships_to_resource.

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

@zachdaniel zachdaniel merged commit 08efa80 into ash-project:main Feb 13, 2026
45 checks passed
@zachdaniel
Copy link
Contributor

🚀 Thank you for your contribution! 🚀

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