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

Named references #955

Merged
merged 3 commits into from
Nov 9, 2024
Merged

Named references #955

merged 3 commits into from
Nov 9, 2024

Conversation

ABruel
Copy link
Contributor

@ABruel ABruel commented Nov 3, 2024

Add the ability to generate references with custom column names by using :references:<table> as a type.

Also fixes generation to allow for multiple references to the same table as in

$ generate scaffold posts title:string! content:string! written_by:references:users approved_by:references:users

#949 (raised concerns, not the underlying issue)
Fixes #814

@@ -48,7 +48,7 @@ impl MigrationTrait for Migration {
{% for ref in references -%}
.foreign_key(
ForeignKey::create()
.name("fk-{{plural_snake}}-{{ref.0 | plural}}")
.name("fk-{{plural_snake}}-{{ref.1 | plural| snake_case}}")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Use ref.0 to allow multiple references to the same table, otherwise scaffold post created_by:references:users updated_by:references:users would create two fk-posts-users.

@@ -78,8 +78,7 @@ enum {{model}} {
{% endfor %}
}


{% for ref in references -%}
{% for ref in references | unique(attribute="0") -%}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Avoid creating two enums when referencing a table multiple times.

@jondot jondot added this to the 0.13.0 milestone Nov 9, 2024
@jondot jondot merged commit e8191c2 into loco-rs:master Nov 9, 2024
14 of 16 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.

more complex references?
3 participants