开发者

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

Closed. This question needs to be more focused. It is not currently accepting answers.

Want to improve this question? Update the question so it focuses on one problem only by editing this post.

Closed 9 years ago.

Improve this question

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 = 'joe@aol.com';
$user->save();
unset($user);

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

/*
 * Set all users as players
 */
$users = ORM::fact开发者_开发技巧ory('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.


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


Please make sure that you can handle many to many relationships.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜