loco-rs / loco

🚂 🦀 The one-person framework for Rust for side-projects and startups
https://loco.rs
Apache License 2.0
5.36k stars 226 forks source link

Support custom field name for references #318

Open narup opened 10 months ago

narup commented 10 months ago

Feature Request

For a generate model command such as - cargo loco generate model posts title:string! content:text user:references it would be good to allow some syntax to have a different field name for user. Right now, it generates user_id column name but what if I want to generate something like owner_id so that I can have multiple references to the users table such as requester_id all referencing the users table

Something like? cargo loco generate model posts title:string! content:text user:requester_id:references ?

Describe alternatives you've considered For now, I am just using a different migration to rename the column but default support on the cli command itself would be useful

I can try to raise a PR if this is desired

jondot commented 10 months ago

Hi, The solution you suggest looks good. If you want to work on a PR we can accept it.

Note: As far as I know, in Rails -- they direct you to do this kind of customization via editing the migration file, so they do not provide a solution via CLI generator. But the solution you suggest looks interesting, so I think it can be good.

jondot commented 10 months ago

@narup did you get a chance to work on a PR for your suggestion? anything I can help with?

HiImJulien commented 9 months ago

@jondot If @narup hasn't started working on it, I'll like to give it a shot. I dived a bit into the source yesterday and I think I know where and how to fix this.

OnekO commented 3 weeks ago

Coud be nice to have this feature. Is anyone working on it?