2016-10-24 17:09:26
PHP Data Access Libraries (ORM, ActiveRecord, Persistence)
Site webhttp://www.yiiframework.com/
Github / Bitbucket / Sourceforgehttps://github.com/yiisoft/yii2
Dernière version2.0.10
How schema is defined?Active record magic properties.
Code generationOui Web and console generator https://github.com/yiisoft/yii2-gii
Can be used in Any Framework- Planned in 2.1.x
Automated CacheOui
Anti-patterns (purposely included)
Simplicité5.0 2 notes
Enterprise Compliance4.5 2 notes
Minimum PHP Version5.4
Basic Features
PDO SupportOui
NoSQL Integrate TransparentlyOui Avialable cross sql and nosql datababase relations
How to invoke db-vendor-specific extensions?Oui SQL - Query Builder.
Array as a persistenceOui https://github.com/yii2tech/filedb
RestAPI as a persistence- To extend BaseActiveRecord
JSON string as a persistence- To extend BaseActiveRecord
Same model, multiple persistences- (no docs)
Persistence Mapping (must support C,R,U,D)
Table Name MappingOui Using static method of active record. http://www.yiiframework.com/doc-2.0/guide-db-active-record.html#declaring-ar-classes
Field Name MappingOui
Map Entity to SubQuery- table = new Expression(..)
Map property to expression- (couldn't find docs)
Map native types (DateTime)Oui Active record behaviors
User-defined types (e.g. "23 USD")Oui Active record behaviors
Map field of related Entity ('currency' = currency_id->Model Currency.name)Oui $model->currency->name
Map field to sub-query on related entity (Client.balance = Client->orders->sum(total))- (couldn't find docs)
Entity to join multiple tables (adding new record populates both tables)Non No native support.
NoSQL (must be transparent to domain logic)
MongoDB supportOui https://github.com/yiisoft/yii2-mongodb
Criteria, Scope, Conditions (Model will refuse to work with records that does not match criteria)
Support model-level criteriaNon
Soft-deleteOui Events and behaviors
Domain Model CriteriaNon Only for specific query: User::find()->byEmail('...')->active()->one()
Expression-based conditionNon Only for query: User::find()->andWhere('...')->all()
Criteria Compliance (new record must match condition)Non
Dynamic criteriaNon Only Querying: User::find()->where(['a' => '1', 'b' => true])->all();
Query Building (Convert Model into Query object for further SQL tweaking)
Convert Model into Query ObjectOui \yii\db\ActiveRecord::find()
Raw expressionOui new \yii\db\Expression('...')
Nested/Composite Queries/ExpressionsOui Expression can be in any part of query
Reference domain-model field in queryNon Field is class property.
field, where, order, limitOui \yii\db\ActiveQuery
options, rollup, partition
UPDATE, DELETE, INSERT query buildingOui
REPLACE, TRUNCATE- Throught raw sql in \yii\db\Command
SHOW, DESCRIBE, CALL- Throught raw sql in \yii\db\Command
ALTER, CREATE query buildingOui
User-defined query templateOui (please link doc)
OR deep nested conditionsOui
Use Domain logic in multi-record updateNon
Data Fetching (different ways to retrieve data from database)
Get All Data (2x array)Oui \yii\db\Query::all()
Associative Array (id=>value)
Single rowOui \yii\db\Query::one()
Single ValueOui \yii\db\Query::scalar()
Single ColumnOui \yii\db\Query::column()
Bypass persistence mapping
Loading and Saving individual records
Load by IDOui User::findOne(1)
Load by other fieldOui User::findOne(['id' => 1])
Load if expressionOui User::findOne('...')
Load respects Scope (model-level condition)- User::find()->where(...)->andWhere(...)->one()
Specify fields to loadOui User::find()->select([])->one()
Save only sends dirty fieldsOui
Guarded / Fillable properties
Object Hierarchy Model
Admin extends User (is_admin=1)Non Can be done as wrapper: User::findAdmin(..) or custom CDbCriteria
Model that represent Orders of single User.Non
Extend model, add Join (Disjoined SubTypes)Non
Extend model change table
Relations/References (One model can relate to another model. NOT A TABLE JOIN)
Model can define relation to other ModelOui Relations
One-to-many traversal strategyUses classical eager/lazy loading approach. with() can help pre-fetch the data for related entities.
Many-to-ManyOui relations() method of an entity can define.
Deep Many-to-Many traversal.- only with "to-one" references: $book->author->address->street; Executes multiple queries.
Cross-Persistence traversal- No docs.
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 operationOui
Hooks for C,R,U,D operationsOui
Persistence-specific hooks (to modify Query)- (no docs)
User-defined hooksOui
Mapping strategy
How to set-up
Store old/new field valuesOui
Date of creation, modificationOui \yii\behaviors\TimestampBehavior
User/IP creation, modificationOui \yii\behaviors\BlameableBehavior
Store incremental revisions
Revert action (undo)Non
Custom eventsOui
Custom fields, tableOui
Store in CSVNon
Access to record-specific history- Through a custom query.
Access Control
Implementation Strategy
Single-system global access scopeNon
Meta-information (allows exploration by UI widgets)
Implementation StrategyWidgets must specify data types manually, while dataProvider is used for fetching the data stream.
UI Widget can fetch list of Model Fields- \yii\grid\GridView, \yii\widgets\ListView
UI Widget can get Field type, default value, caption, hint- (no docs)
field storing reference to another Model can map into DropDownNon
J'aime 0
  • 2016-10-18 22:11:55
    2016-10-24 17:09:26
  • Produits
  • Publique
  • Creative Commons License CC-BY-SA 3.0 / GNU FDL


Laisser un commentaire

Créer des tableaux comparatifs ou listes sur tout !

C'est gratuit et rapide de créer des tableaux originaux

Créer un tableau