Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Features needed when building a ORM with PHP? [closed]

Tags:

php

orm

I have never really appreciated ORM's so I think that the only way to remedy this is to build a basic one myself so I can see what all the hubbub is. So with that in mind, what are the basic features I would need to include to make a semi-usable ORM?

As far as I can tell, it would basically need to work like this for the end programmer:

/*
 * Create a user
 */
$user = new User();
$user->name = 'Joe';
$user->email = '[email protected]';
$user->save();
unset($user);

/*
 * Create a game
 */
$game = new Game();
$game->name = 'soccer';
$game->save();

/*
 * Set all users as players
 */
$users = ORM::factory('users');
$users = $users->findAll();
foreach ( $users as $user ) {
    $user->setGame($game);
    $user->save();
}
unset($users);

/*
 * Get all games and show all users
 */
$games = ORM::factory('games')->findAll();
foreach( $games as $game ) {
    print $game->name;
    print 'Users in game:';
    foreach( $game->users as $user ) {
        print $user->name;
    }
}

Each model class would extend the ORM class which would have all the basic methods

  • find($id)
  • findAll($where)
  • save()

Other usefull features would be things like:

  • Able to request rows with a certain id User::find(34)
  • Able to limit result rows with WHERE like options
  • Able to tie one row object to many rows from another table. (1 to many)
  • Query building so that the SQL was written automatically.

Could anyone else tell me what I would need. I've been looking at some of the libraries like Doctrine, EZPDO, dORM, and KohanaPHP but I can't seem to find a library that is easy to digest to figure out what the feature list would need to be to tackle this project.

I found an image detailing some of ruby's offerings and some more info on the IgnitedRecord Project.

like image 762
Xeoncross Avatar asked Nov 03 '09 02:11

Xeoncross


1 Answers

Here is a list of basic and extended features ORM is supposed to have: http://madgeek.com/Articles/ORMapping/EN/mapping.htm

like image 114
Vladislav Rastrusny Avatar answered Nov 11 '22 14:11

Vladislav Rastrusny