2016-10-21 16:22:28
PHP Data Access Libraries (ORM, ActiveRecord, Persistence)
Github / Bitbucket / Sourceforgehttps://github.com/yiisoft/yii2
Latest version2.0.10
How schema is defined?Active record magic properties.
Code generationYes Web and console generator https://github.com/yiisoft/yii2-gii
Can be used in Any Framework- Planned in 2.1.x
Automated CacheYes
Anti-patterns (purposely included)
Simplicity5.0 1 rating
Enterprise Compliance4.0 1 rating
Minimum PHP Version5.4
Basic Features
PDO SupportYes
NoSQL Integrate NativelyYes Avialable cross sql and nosql datababase relations
Vendor-specific features
Array as a persistenceYes https://github.com/yii2tech/filedb
RestAPI as a persistence- To extend BaseActiveRecord
JSON string as a persistence- To extend BaseActiveRecord
Same model, multiple persistencesYes
Persistence Mapping (must support C,R,U,D)
Table Name MappingYes Using static method of active record. http://www.yiiframework.com/doc-2.0/guide-db-active-record.html#declaring-ar-classes
Field Name MappingYes
Map Entity to SubQuery
Map property to expressionYes
Map native types (DateTime)Yes Active record behaviors
User-defined types (e.g. "23 USD")Yes Active record behaviors
Map field of related Entity ('currency' = currency_id->Model Currency.name)Yes $model->currency->name
Map field to sub-query on related entity (Client.balance = Client->orders->sum(total))Yes
Entity to join multiple tables (adding new record populates both tables)- Using events and behaviors
NoSQL (must be transparent to domain logic)
MongoDB supportYes https://github.com/yiisoft/yii2-mongodb
Criteria, Scope, Conditions (Model will refuse to work with records that does not match criteria)
Soft-deleteYes Events and behaviors
Domain Model CriteriaYes User::find()->byEmail('...')->active()->one()
Expression-based conditionYes User::find()->andWhere('...')->all()
Criteria Compliance (new record must match condition)
Dynamic conditionsYes User::find()->where(['a' => '1', 'b' => true])->all();
Query Building (Convert Model into Query object for further SQL tweaking)
Convert Model into Query ObjectYes \yii\db\ActiveRecord::find()
Raw expressionYes new \yii\db\Expression('...')
Nested/Composite Queries/ExpressionsYes Expression can be in any part of query
Reference domain-model field in query
field, where, order, limitYes \yii\db\ActiveQuery
options, rollup, partition
UPDATE, DELETE, INSERT query buildingYes
REPLACE, TRUNCATE- Throught raw sql in \yii\db\Command
SHOW, DESCRIBE, CALL- Throught raw sql in \yii\db\Command
ALTER, CREATE query buildingYes
User-defined query templateYes
OR deep nested conditionsYes
Use Domain logic in multi-record update
Data Fetching (different ways to retrieve data from database)
Get All Data (2x array)Yes \yii\db\Query::all()
Associative Array (id=>value)
Single rowYes \yii\db\Query::one()
Single ValueYes \yii\db\Query::scalar()
Single ColumnYes \yii\db\Query::column()
Bypass persistence mapping
Loading and Saving individual records
Load by IDYes User::findOne(1)
Load by other fieldYes User::findOne(['id' => 1])
Load if expressionYes User::findOne('...')
Load respects ScopeYes User::find()->where(...)->andWhere(...)->one()
Specify fields to loadYes User::find()->select([])->one()
Save only sends dirty fieldsYes
Guarded / Fillable properties
Object Hierarchy Model
Admin extends User (is_admin=1)Yes Using scope. User::find()->isAdmin()->all();
ShippedOrder extends Order
Extend model, add Join (Disjoined SubTypes)
Extend model change table
Relations/References (One model can relate to another model. NOT A TABLE JOIN)
Model can define relation to other ModelYes Relations
One-to-many traversal strategy
Deep TraversalYes $book->author->address->street;
Cross-Persistence traversalYes
Multi-persistence Mapping (some data from SQL, others MongoDB)
Multi-persistence join
UNION existing models
Multi-persistence UNION
Multi-persistence value linking (current_sensor_value)
Behaviours / Hooks
Before/After operationYes
Hooks for C,R,U,D operationsYes
Persistence-specific hooks (to modify Query)Yes
User-defined hooksYes
Mapping strategy
How to set-up
Store old/new field valuesYes
Date of creation, modificationYes \yii\behaviors\TimestampBehavior
User/IP creation, modificationYes \yii\behaviors\BlameableBehavior
Store incremental revisions
Revert action (undo)No
Custom eventsYes
Custom fields, tableYes
Store in CSVNo
Access to record-specific history- Through a custom query.
Access Control
Implementation Strategy
Single-system global access scope
Meta-information (allows exploration by UI widgets)
Implementation Strategy
UI Widget can fetch list of Model FieldsYes \yii\grid\GridView, \yii\widgets\ListView
UI Widget can get Field type, default value, caption, hintYes \yii\grid\GridView, \yii\widgets\ListView, \yii\widgets\DetailView
field storing reference to another Model can map into DropDown
  • 2016-10-18 22:11:55
    2016-10-21 16:22:28
  • Products
  • Public
  • Creative Commons License CC-BY-SA 3.0 / GNU FDL

Build comparison tables or lists about everything !

It's free and fast to publish data into original tables

Create a table