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

Generate references/associations based on custom JSON file originally created from foreign keys #82

Closed
deksden opened this issue May 20, 2016 · 2 comments

Comments

@deksden
Copy link
Contributor

deksden commented May 20, 2016

Just an idea: as for now, we importing FKs as simple references for our models - we did not generate any associations.

But many FKs actually are 1:M or 1:1 relations (maybe some are M:M via some table). Converting references int associations is 100% manual process as for now.

This can be changed in some way.

Sequelize-auto (SqA) did not know about proper schema and associations between models, but whole process can be iterative with involving user:

  1. SqA makes initial import of some tables and generate JSON file with list of references based of FKs (optionally, all FKs are converted to references in models); each reference in JSON file marked as "simple reference";
  2. user makes some changes in JSON to modify list of references and specify proper type of relation as 1:M, 1:1 relations for some or all discovered references (convert "simple reference" to "specified reference");
  3. SqA makes second pass using same JSON file, for specified references SqA will generate proper model associations (hasOne, hasMany, etc), for "simple references" or newly discovered references (maybe user adds some more tables to import, or maybe user did not process whole file) that references optionally converted to references in model (like today);

Not sure how we should process M:M relations, but 1:1 and 1:M looks not so complicated.

@geekflyer
Copy link

fyi: http://www.pg-generator.com/ does that already. It also supports M:N relationships etc.

steveschmitt added a commit that referenced this issue Nov 3, 2020
) (#369)

Add precision to DECIMAL, DOUBLE, and FLOAT types
Add array types to TypeScript definitions
@steveschmitt
Copy link
Collaborator

Added belongsTo/hasOne/hasMany to the generated initModels function in release 0.7.0.

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

3 participants