Welcome Guest, Not a member yet? Register   Sign In
There is any function to autogenerate the DataMapper models based on SQL tables?
#1

[eluser]Zequez[/eluser]
Hello ^^
I'm new in CodeIgniter, started reading documentation of it and DataMapper a couple of days ago.

I was thinking that given the database normalization it wouldn't be hard to autogenerate the models automatically, so maybe there is a function to do so that I has't found. So after I write the script myself I think it would be better to ask Tongue

By autogenerate I mean the files with the named classes, in conjunction with "$has_many" and "$has_one" arrays and some other autodetected things

There is?
#2

[eluser]WanWizard[/eluser]
No, there isn't.

It would require a complete data dictionary in your models describing the tables to make it useful, and if automated it would also slow datamapper down, which is unacceptable.

If something automated should be build, it should be the other way around, with a stand-alone system (like migrations) that would generate your tables, indexes, constaints if any, and your models, based on a central repository. This should also contain a versioning system (again, like migrations) that would allow you to up- and downgrade.

This kind of system is currently not in the scope of the project, but feel free to register a feature request at http://bitbucket.org/wanwizard/datamapper/issues, so the idea doesn't get lost.
#3

[eluser]Zequez[/eluser]
[quote author="WanWizard" date="1307556982"]No, there isn't.

It would require a complete data dictionary in your models describing the tables to make it useful, and if automated it would also slow datamapper down, which is unacceptable.

If something automated should be build, it should be the other way around, with a stand-alone system (like migrations) that would generate your tables, indexes, constaints if any, and your models, based on a central repository. This should also contain a versioning system (again, like migrations) that would allow you to up- and downgrade.

This kind of system is currently not in the scope of the project, but feel free to register a feature request at http://bitbucket.org/wanwizard/datamapper/issues, so the idea doesn't get lost.[/quote]

Sorry, I think you misunderstood me, I didn't meant to generate everything "on the fly" every time the application is ran. I just meant to make a function that would be run ONCE to analyze a database or just a table and autogenerate the BASE structure of all the required models. Is not big deal anyway, but when you have more than 10 tables it becomes a little bit of a hassle to create a file and the class for each one Tongue
#4

[eluser]WanWizard[/eluser]
Ok, the other way around.

No, that doesn't exist either. And this is not going to happen either, for the simple reason that basically a model is an empty class:
Code:
class Modelname extends Datamapper {
}

// end of file

This is enough to get a working model. To be able to add the relations ($has_one and $has_many properties) you need to know your database structure, which will be hard to deduct from your database tables. Creating your model is a one-time job, and shouldn't take more than a minute or so.

It shouldn't be to hard to come up with something, but it's not going to be very high on my long list of things to do...
#5

[eluser]Zequez[/eluser]
[quote author="WanWizard" date="1307566626"]Ok, the other way around.

No, that doesn't exist either. And this is not going to happen either, for the simple reason that basically a model is an empty class:
Code:
class Modelname extends Datamapper {
}

// end of file

This is enough to get a working model. To be able to add the relations ($has_one and $has_many properties) you need to know your database structure, which will be hard to deduct from your database tables. Creating your model is a one-time job, and shouldn't take more than a minute or so.

It shouldn't be to hard to come up with something, but it's not going to be very high on my long list of things to do...[/quote]

haha ok, thanks Tongue
I guess I'm too lazy Tongue
#6

[eluser]WanWizard[/eluser]
First attempt to hack something. Could you run this controller in your environment, and tell me if you see any obvious mistakes?

It doesn't write anything yet, just echo's the model code generated, and dumps the errors detected while processing your database tables.




Theme © iAndrew 2016 - Forum software by © MyBB