PhpBURN vs Doctrine – Model Construction

Posted by on Jul 15, 2010 in Blog | 0 comments

I’m going to do a little comparative between PhpBURN vs Doctrine, showing strongest points in PhpBURN in relation to that we consider the bigest ORM framework in market.

The goal here it’s to show that when you use PhpBURN you have already set all your needs like persistend methods and all “stuff” then you don’t need to keep setting facade methods, you just go using them.

First of all let’s see how to build a EXTENDABLE Model in PhpBURN:

class BaseUser extends PhpBURN_Core {
	public $_tablename = 'users';
	public $_package = 'phpburn';
	
	public function _mapping() {
		$this->getMap()->addField('id','id','int',4,array('primary' => true, 'autoincrement' => true));
		$this->getMap()->addField('username', 'username', 'varchar', 255, array());
		$this->getMap()->addField('password', 'password', 'varchar', 255, array());
		
		$this->getMap()->addRelationship('Groups',self::ONE_TO_MANY,'UserGroup','id','user_id');
	}
}

class User extends BaseUser {
	
}

/* You do Not need any more configuration because the PhpBURN works as ORM, DAO, ActiveRecord and DataMapper, you're all set

Now le’ts see it’s equivalent in Doctrine:

/**
 * This class has been auto-generated by the Doctrine ORM Framework
 */
abstract class BaseUser extends Doctrine_Record
{

  public function setTableDefinition()
  {
    $this->setTableName('user');
    $this->hasColumn('id', 'integer', 4, array('primary' => true, 'autoincrement' => true));
    $this->hasColumn('username', 'string', 255);
    $this->hasColumn('password', 'string', 255);
  }

  public function setUp()
  {
    $this->hasMany('Group as Groups', array('refClass' => 'UserGroup',
                                            'local' => 'user_id',
                                            'foreign' => 'group_id'));

    $this->hasMany('UserGroup', array('local' => 'id',
                                      'foreign' => 'user_id'));
  }

}

// Add custom methods to system/application/models/User.php

/**
 * This class has been auto-generated by the Doctrine ORM Framework
 */
class User extends BaseUser
{
  public function setPassword($password)
  {
    $this->password = md5($password);
  }
}

/**
 * This class has been auto-generated by the Doctrine ORM Framework
 */
class UserTable extends Doctrine_Table
{
  public function retrieveAll()
  {
    $query = new Doctrine_Query();
    $query->from('User u');
    $query->orderby('u.username ASC');

    return $query->execute();
  }
}

Both frameworks has Reverse Engineer and Foward Engineer to create Model and Database Tables.

Leave a Reply

You must be logged in to post a comment.