Welcome Guest, Not a member yet? Register   Sign In
Auto-generating default CRUD code for models
#1

[eluser]Unknown[/eluser]
I have been reading up on auto-generating repetitive bits of code for basic CRUD functionality, and I was wondering if anyone uses this with CI yet.

Basically, what this idea means is that for every table in your database, you can create a default model that has all the common actions in. Find, create, count rows, etc... That way, you don't have spend time coding tedious, repetitive code for every single table in your database. The only thing you'd have to do, is adding custom functionality for very specific actions.

I am new to CI (and sold - this is THE framework for me), and while reading the documentation I figured the Active Record class does something similar. It offers easy, human readable functions for CRUD. The big difference in my eyes, is that it doesn't reside in a table-specific model. (So it advocates a non-proper use of the MVC? Am I understaning this properly?)

In my search on the forums I have found a few threads that touch the subject:

http://ellislab.com/forums/viewthread/71815/
Where member Seppo writes: "I usually define a model per entity with 6 basic methods, 5 public (fetchlist, get, count, save, delete), 1 private (parse_filters) and one or many classes related to that model that will store the information, can have some small logic, but nothing DB related, in that case they’ll contact the model."

http://ellislab.com/forums/viewthread/61192/
This seems to be an extension on the Active Record class

I think the first link comes closest to what I mean. I'm interested to see who else uses this method, and if/how they autogenerate their code for this.
#2

[eluser]GSV Sleeper Service[/eluser]
you may want to take a look at 'rabbit forms' - http://ellislab.com/forums/viewthread/74393/
#3

[eluser]webthink[/eluser]
I use a variation of this http://ellislab.com/forums/viewthread/61192/ (look for the chromice mod)
It's an ORM and CRUD in one. I'm not a fan of autogenerated code. I'd rather have an abstracted solution. This accomplishes that.
I create the model files myself but they're all of about 5 lines each.
#4

[eluser]Daniel Eriksson[/eluser]
[quote author="GSV Sleeper Service" date="1206630274"]you may want to take a look at 'rabbit forms' - http://ellislab.com/forums/viewthread/74393/[/quote]

I think the OP is more interested in something like MyGeneration (http://www.mygenerationsoftware.com/) but for PHP.

/Daniel
#5

[eluser]webthink[/eluser]
Yeah I think the confusion here comes from the need to handle CRUD for models as opposed forms. There was some scripts around that did the generation he's talking about and I can't for the life of me remember what they were. There are also a number of debates on the merits (or lack thereof) of code-generation solutions. I'm of the opinion that model abstraction rather than model generation is the way to go but to each their own.
#6

[eluser]Daniel Eriksson[/eluser]
I recently used MyGeneration in an ASP.NET (C#) project and I really liked the way it allowed us to manage rows as objects and get automatic inserts/updates done. I'm not sure yet if I prefer a generic ORM or a table-specific one that I have to generate myself. There are pros and cons to both approaches.

By the way, I just noticed that MyGeneration comes with templates for generating PHP classes also. I'll have to try that out...

/Daniel
#7

[eluser]webthink[/eluser]
Codecrafter is the project I was thinking of. I believe it's designed to do exactly what the OP is after.
#8

[eluser]Daniel Eriksson[/eluser]
Another solution is Propel.

Some more ORM software: http://en.wikipedia.org/wiki/List_of_obj...g_software

/Daniel
#9

[eluser]Unknown[/eluser]
[quote author="webthink" date="1206632979"]Codecrafter is the project I was thinking of. I believe it's designed to do exactly what the OP is after.[/quote]

Thanks for the replies so far!

Codecrafter looks exactly like what I had in mind. I have briefly read the PDF on their site, and it looks promising. The screenshots are to low-res to make out if this does exactly what I had in mind, though.

I best give this a whirl, and read up on some forum posts on this.

Thanks again, everyone! Smile


EDIT: on searching I come across a lot of threads I missed in my research... I guess I hadn't been using the proper search terms
#10

[eluser]Unknown[/eluser]
Ya basically there needs to be a way of auto-generating this tedious model class for CRUD operation. Every time i create a table i need to do that which basically kills lot of my time. But model generation isnt so tough i think. Codeigniter should make a good effort to do this as soon as possible. I'm trying my own way. Other than CRUD operations and typical getter, setter i generate some select methods like readUsingPrimarykeys and readUsingUniqueKeys and updateUsingUniqueKeys also methods for composite keys too. But the big question arrises when we need to select multiple rows, which is against single row single object concept. I tried doing collection objects and its doing great for me. Anyone has any new ideas???

Thanks
Yamin




Theme © iAndrew 2016 - Forum software by © MyBB