How to generate entities from database schema using cycle
Once I create Entities I usually run commands to sync and generate database automatically according to my entities. Is there a way to make this process reverse? I mean, Can I generate entities from existing database in mysql?
Yes, but we do not provide this instrument out of the box. However, we provide database introspection and code generation libraries which we usually use for such purpose:
https://spiral.dev/docs/component-reactor https://spiral.dev/docs/database-introspection
Are there any plans on developing and including this in the core of cycle/orm in the future?
I am currently working on a proof of concept to create something like this, and I have a couple of questions?
- Are there any performance considerations when you do not supply a "belongs to" reference?
- My current alpha code detects many-to-many relations both ways (entityA -> through <-entityB) and (entityB -> through <-entityA). If the auto generated entities have this relation is cycle orm smart enough to be aware of this, and does this have a downside to specify the many-to-many relation both ways?
Hi,
Yes, we want to include it into core but we don’t have time for this priority yet, so any help will be appreciated (can be a plug-in). We have almost everything to make it happen: schema builder, db introspection.
- not sure, can you provide more details?
- cycle is fine when both sides have it, but your domain code need to be aware of which side of relation to use. We usually make only one relation writable and secondary as ready-only (cascade=false).
not sure, can you provide more details?
It was just a thought, so I will assume that this will not impact anything
cycle is fine when both sides have it, but your domain code need to be aware of which side of relation to use. We usually make only one relation writable and secondary as ready-only (cascade=false).
That is a great tip.
I am currently modifying an entity builder I created for another project. Which already had some of the features as found in: https://spiral.dev/docs/component-reactor https://spiral.dev/docs/database-introspection
Once I have everything working I think I would be able to do the same using above mentioned packages.