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

Missing module imports for ManyToOne, OneToMany field types #341

Open
metmirr opened this issue Apr 16, 2020 · 2 comments
Open

Missing module imports for ManyToOne, OneToMany field types #341

metmirr opened this issue Apr 16, 2020 · 2 comments

Comments

@metmirr
Copy link

metmirr commented Apr 16, 2020

Do you want to request a feature or report a bug?

Bug

Generating model with warthog generate command does not add import statement for related fields. Adding additional logic to model.ts.ejs I was able to run it successfully. Here is my commit: Joystream@e9b7eeb

@goldcaddy77
Copy link
Owner

Good call out. Your version will work with your particular cliGeneratePath, but would break for others. To make this work with any CLI_GENERATE_PATH, we'll need to do something similar to what's done here: https://github.com/metmirr/warthog/blob/master/src/cli/commands/generate.ts#L41

Perhaps pass a getFolderForModel function into props and then call it with the other model name. Something like:

function getFolderForModel(name: string) {
  const names = {
      className: toolbox.strings.pascalCase(name),
      camelName: toolbox.strings.camelCase(name),
      kebabName: toolbox.strings.kebabCase(name),
      // Not proper pluralization, but good enough and easy to fix in generated code
      camelNamePlural: toolbox.strings.camelCase(name) + 's'
    };

    // Allow folder to be passed in or pulled from config files
    const cliGeneratePath =
      options.folder ||
      path.join(config.get('ROOT_FOLDER'), '/', config.get('CLI_GENERATE_PATH'), '/');

    // TODO:DOCS
    // Allow interpolation of the above names into the generate path like './src/${kebabName}'
    const destFolder = supplant(cliGeneratePath, names);

I imagine you'll also need to use path.resolve to make sure the path imports are relative.

Do you want to try to put in a PR for this?

@metmirr
Copy link
Author

metmirr commented Apr 22, 2020

Definitely! I need this to work properly but I can do it on weekend.

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

No branches or pull requests

2 participants