-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
docs: fix javascript usage examples #7031
Conversation
I saw issue #6997 where that reported the example code wasn't working. |
docs/usage-with-javascript.md
Outdated
require("./entity/Post"), | ||
require("./entity/Category") | ||
new EntitySchema(require("./entity/Post")), | ||
new EntitySchema(require("./entity/Category")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure this is necessary? We pass classes that are marked with @Entity
into the connections all the time and it seems to work quite well. Why wrap these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
The items in the entities array should be either a constructor function with @Entity()
metadata, or an instanceof EntitySchema
, or string that is a file glob path to modules that export one of those things. Since this is an example using plain javascript, it needs to be an EntitySchema. This is the same technique for defining entities as described in Separating Entity Definition.
If you try to run the example code as shown, it will throw a RepositoryNotFoundError. The code in the example repo linked at the bottom of this document works correctly. This updates the example code in the document itself to match the code in the repo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, didn't read the whole example. Sorry :)
Can we instead create the entity schemas in the entity objects instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I like that better. I think the example repo does it in the entities array for importing from JSON, but that's not the case here. I will revise the pull request. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I used var EntitySchema=require("typeorm").EntitySchema
in the schema files. Is that ok?
(I assume it's using var for compatibility with ES5, but I don't know if we really need to do that anymore.)
d202c56
to
28eb03c
Compare
28eb03c
to
99f92df
Compare
Anything else I can do for this? |
Thank you for contribution! 🎉 |
* typeorm-0.2.30: (212 commits) version bump docs: fix javascript usage examples (typeorm#7031) fix: resolve migration for UpdateDateColumn without ON UPDATE clause (typeorm#7057) fix: Error when sorting by an embedded entity while using join and skip/take (typeorm#7082) fix: resolves Postgres sequence identifier length error (typeorm#7115) feat: closure table custom naming (typeorm#7120) feat: relations: Orphaned row action (typeorm#7105) docs: fix invalid code block in "find many options" (typeorm#7268) docs: Embodying the example (typeorm#7116) docs: document withDeleted option (typeorm#7132) fix: return 'null' (instead of 'undefined') on lazy relations that have no results (typeorm#7146) (typeorm#7147) docs: update cascade options (typeorm#7140) docs: add .ts to supported ormconfig formats (typeorm#7139) fix: improve stack traces when using persist executor (typeorm#7218) refactor: remove Oracle multirow insert workaround (since typeorm#6927) (typeorm#7083) feat: add NOWAIT and SKIP LOCKED lock support for MySQL (typeorm#7236) docs: update OneToMany grammar (typeorm#7252) feat: JavaScript file migrations output (typeorm#7253) docs: update Repository.ts (typeorm#7254) chore: update dependency cli-highlight to v2.1.10 (typeorm#7265) ...
Description of change
Updated Javascript usage example in docs/usage-with-javascript.md and docs/zh_CN/usage-with-javascript.md to pass EntitySchema objects in the ConnectionOptions instead of plain objects and changed type:"string" in the schemas to type:"varchar". Also updated docs/zh_CN/usage-with-javascript.md to use "entities" instead of "entitySchemas" in the ConnectionOptions.