• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MY_Model Database Abstraction Library -> Usefull or Useless ???

#1
[eluser]Unknown[/eluser]
Hello Everybody,

I would like to receive a feedback about a basic idea I have, that is related to the Model part of the MVC approach that I learned through the use of CI. The idea is as follows :

One recursive problem I find when I develop a brand new web application is the database layout that must match with its corresponding models. When I change something in a table, I have to modify my model as well.

Indeed I know that a good project planning involves creating the database model BEFORE coding it ^^ but because I don't have the basic knowledge of application pre-development, I just code my app "on the fly" and need to modify both database and model everytime.

My question is as follows :

Do you think it could be usefull to have a model that adapts the database to itself instead of having to adapt the model to the database structure. In other words, do you see an interest in having a few privates methods within a model that makes this model modify the database "on the fly".

For example let's say I want to create a Car Model, I would have to create let's say a Brand property, a Color property and a Model property. Once my model is finished, it could check to see if it can find the 'cars' table with only (and not more) three columns called 'Brand', 'Color' and 'Model', PLUS an "id" column and that's all. At this point a few possibilities arise :

1 - The table does not exists and the Model loads a particular method to create the table.
2 - The table exists but its structure does not match the exact structure of the model, then the models modify the structure without removing any table rows but only adapting the table structure to its own structure.
3 - The table exists and its structure match the structure of the model, everything's all right.

In this case, if I need to add a new column into my table, let's say 'Engine', I just have to declare a new property called 'Engine' with a default value of "Default" and the model will by itself update the table and its rows by adding a new column "Engine" and set all the existing rows with a "Default" value within the brand new "Engine" column.

Now and to finish, first of all pardon me for my french-like english ^^
And second : Can this concept be usefull or useless ? Maybe is there already another existing solution ? Or maybe there's no need to think this way : CI can already do that for you (maybe use some of the scaffolding functions within the model) ! Or maybe: this is a stupid idea, here's why: ... !

Whatever you think about this idea, please post your feelings ^^

Sincerely Yours ...

#2
[eluser]Bramme[/eluser]
I get your idea, and I see why it COULD be useful. If no such thing exists, you could spend your time writing code that would do this for you, after all, it's just a bunch of if's and mysql_queries. However, the MVC approach requires some amount of planning. I think you'd spend your time much better simply learning to plan out certain tasks.
Thinking about how you want to do/achieve something is just better coding karma imo, then just trial and error.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.