Helper classes (traits) for Propel2 ORM.
This trait is a workaround for the Propel bug that you cannot use joinWith()
methods anymore when setting tables to readOnly="true"
in Propel's schema.xml
file. So instead of making tables "readonly" in the scheme just add this trait to every child model you want to make readonly.
For details see propelorm/Propel2#629
Example usage:
<?php
use Base\User as BaseUser;
use Ansas\Propel\Helper\ReadOnly;
class User extends BaseUser
{
use ReadOnly;
}
The default behavior "versionable" does not seem to work well with relations and in combination with other behaviors. Therefore I wrote a "simple trait" that does NOT consider versions of related tables. All methods can be used as before.
Three things have to be implemented to use this trait:
- Use the trait in the desired class
- Add the following constant with the name of the versionable behavior active records class (e. g. for an 'Account')
- Optionally add the constant for column names (in default PhpName notation) to skip when populating object
Example usage:
<?php
use Base\User as BaseUser;
use Ansas\Propel\Helper\SimpleVersionableBehavior;
class User extends BaseUser
{
use SimpleVersionableBehavior;
/**
* Class name for versionable behavior active records
*/
const VERSIONABLE_CLASS = 'UserVersion';
/**
* Column names (in default PhpName notation) to skip when populating this with version entry
*/
const VERSIONABLE_POPULATE_SKIP_COLUMNS = ['UpdatedAt', 'Version'];
}
This trait makes validation of an object quite easy.
Methods:
protected function addValidationError($key, $value, $overwrite = true)
protected function resetValidation()
public function getValidationErrors()
public function hasValidationErrors()
abstract protected function doValidate();
- Write tests
Everybody can contribute to this package. Just:
- fork it,
- make your changes and
- send a pull request.
Please make sure to follow PSR-1 and PSR-2 coding conventions.
MIT license (see the LICENSE file for more information).