{"id":252531,"date":"2015-03-06T04:55:04","date_gmt":"2015-03-06T00:55:04","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=252531"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=252531","title":{"rendered":"PHPixie 3.0 ORM \u0438\u043b\u0438 \u043d\u043e\u0432\u044b\u0439 \u0432\u0437\u0433\u044f\u0434 \u043d\u0430 ActiveRecord"},"content":{"rendered":"<p>     \t<img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/a9e\/60d\/e1d\/a9e60de1db7f9c18a643766e8aea6f4e.png\" alt=\"image\" align=\"right\"\/> \u0423\u0436\u0435 \u0437\u0430\u043a\u043e\u043d\u0447\u0435\u043d \u0434\u043e\u043b\u0433\u043e\u043e\u0431\u0435\u0449\u0430\u043d\u043d\u0430\u044f \u0442\u0440\u0435\u0442\u044c\u044f \u0432\u0435\u0440\u0441\u0438\u044f <a href=\"http:\/\/phpixie.com\">PHPixie<\/a> ORM \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430. \u041e\u043d \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c \u043e\u0442 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 \u0438 \u043c\u043e\u0436\u0435\u0442 \u0441\u043f\u043e\u043a\u043e\u0439\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u0430\u043c \u043f\u043e \u0441\u0435\u0431\u0435. \u0412 \u0441\u0432\u044f\u0437\u0438 \u0441 \u044d\u0442\u0438\u043c, \u043f\u043e\u043a\u0430 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442\u0441\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u043d\u0430\u0434 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438 \u0438 \u043f\u0438\u0448\u0435\u0442\u0441\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f, \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u043b\u0438 <a href=\"https:\/\/github.com\/PHPixie\/ORM\/blob\/master\/examples\/quickstart.php\">\u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b<\/a> \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0443\u0436\u0435 \u043d\u0430\u0447\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u041e\u0420\u041c. \u041d\u0438\u0436\u0435 \u044f \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044e \u0435\u0433\u043e \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0435\u0449\u0435\u0439 \u043e\u0442 \u0441\u0435\u0431\u044f, \u043d\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0447\u0435\u043c \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u043c \u043f\u043e\u0440\u0430\u0434\u0443\u0435\u0442 \u043d\u0430\u0441 \u044d\u0442\u0430 \u0432\u0435\u0440\u0441\u0438\u044f:  <\/p>\n<ul>\n<li>\u0411\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e ORM \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 Model \u043a\u043b\u0430\u0441\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043a\u0430\u043a \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0442\u0430\u043a \u0438 \u0434\u043b\u044f \u0440\u0435\u043f\u0440\u0435\u0437\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0441\u0430\u043c\u044b\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u0430\u043a \u0434\u0435\u043b\u0430\u044e\u0442 Kohana \u0438 Laravel. PHPixie \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u043b\u0430 \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0430 Repository, Entity \u0438 Query, \u043a\u0430\u0436\u0434\u0430\u044f \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0438\u043c\u0435\u0435\u0442 \u0441\u0442\u0440\u043e\u0433\u043e \u0441\u0432\u043e\u0435 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435.<\/li>\n<li>\u041a\u0440\u043e\u043c\u0435 SQL \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 (SQLite, PostgreSQL, MySQL) \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u0430\u043a\u0436\u0435 Mongo. \u0412\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u0432\u044f\u0437\u0430\u0442\u044c \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f\u043c\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 \u0441 SQL \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438 \u0445\u0440\u0430\u043d\u044f\u0449\u0438\u043c\u0438\u0441\u044f \u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f\u0445 Mongo.<\/li>\n<li>\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c \u0441\u0432\u044f\u0437\u0438 \u043c\u0435\u0436\u0434\u0443 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0431\u0430\u0437\u0430\u043c\u0438 ( \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043c\u0435\u0436\u0434\u0443 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c\u0438 \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u0431\u0430\u0437\u0430\u0445 \u0432 MySQL ) \u043c\u043d\u043e\u0433\u043e ORM \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0432\u043c\u0435\u0441\u0442\u043e join-\u043e\u0432 \u0438 \u0441\u0443\u0431\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. PHPixie \u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0441\u0443\u0431\u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0432\u0441\u0435\u0433\u0434\u0430 \u0433\u0434\u0435 \u044d\u0442\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e.<\/li>\n<li>\u041f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0445 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439 \u0432 Mongo<\/li>\n<li><a href=\"http:\/\/phpixie.com\/coverage\/orm\/ORM\/index.html\">\u041d\u0430 97% \u043f\u043e\u043a\u0440\u044b\u0442\u0430 \u044e\u043d\u0438\u0442 \u0442\u0435\u0441\u0442\u0430\u043c\u0438<\/a> ( \u043f\u043b\u0430\u043d\u0438\u0440\u0443\u0435\u0442\u0441\u044f 100% \u0434\u043e \u043a\u043e\u043d\u0446\u0430 \u044d\u0442\u043e\u0439 \u043d\u0435\u0434\u0435\u043b\u0438), \u0438 \u0435\u0449\u0435 \u043d\u0430 75% \u0444\u0443\u043d\u043a\u0446\u044b\u043e\u043d\u0430\u043b\u043d\u044b\u043c\u0438 \u0442\u0435\u0441\u0442\u0430\u043c\u0438. <\/li>\n<li>\u042d\u0444\u0444\u0435\u043a\u0442\u044b\u0432\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 Query \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c \u0447\u0438\u0441\u043b\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a \u0431\u0430\u0437\u0435. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0432\u0430\u043c \u043d\u0430\u0434\u043e \u0441\u0432\u044f\u0437\u0430\u0442\u044c \u0432\u0441\u0435 \u0442\u043e\u043f\u0438\u043a\u0438 \u0430\u0432\u0442\u043e\u0440\u0430 \u0441 \u043a\u0430\u043a\u0438\u043c\u0438-\u0442\u043e \u0442\u0435\u0433\u0430\u043c\u0438. \u0412 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u041e\u0420\u041c \u0432\u0430\u043c \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u0439\u0442\u0438 \u0442\u043e\u043f\u0438\u043a\u0438, \u043f\u043e\u0442\u043e\u043c \u0442\u0435\u0433\u0438 \u0438 \u0442\u043e\u0433\u0434\u0430 \u0441\u0432\u044f\u0437\u0430\u0442\u044c \u0438\u0445 ( 3 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043a \u0411\u0414 ). PHPixie \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0437\u0430 \u043e\u0434\u0438\u043d \u0437\u0430\u043f\u0440\u043e\u0441. \u041a\u0441\u0442\u0430\u0442\u0438 \u043f\u0440\u0438\u043c\u0435\u0440 \u044d\u0442\u043e\u0433\u043e \u0435\u0441\u0442\u044c \u0432 \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u0435 \u0441\u043d\u0438\u0437\u0443<\/li>\n<\/ul>\n<p>  \u041d\u0430\u0434\u0435\u044e\u0441\u044c \u044f \u0441\u043c\u043e\u0433 \u0432\u0430\u0441 \u0437\u0430\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u0442\u044c, \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440 \u0441 \u0441\u0441\u044b\u043b\u043a\u0438 \u0432\u0432\u0435\u0440\u0445\u0443 \u0432 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0435:<br \/>  <a name=\"habracut\"><\/a><\/p>\n<pre><code class=\"php\">&lt;?php  require_once('vendor\/autoload.php');  $config = new \\PHPixie\\Config();  \/\/\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 $database = new \\PHPixie\\Database($config-&gt;dataStorage(array(     'default' =&gt; array(         'driver' =&gt; 'pdo',         'connection' =&gt; 'sqlite::memory:'     ) )));  \/\/\u0418 \u0441\u0430\u043c\u043e\u0439 \u041e\u0420\u041c $orm = new \\PHPixie\\ORM($database, $config-&gt;dataStorage(array(     'relationships' =&gt; array(         array(             \/\/\u0423 \u0444\u0435\u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u0446\u0432\u0435\u0442\u043e\u0432             'type'  =&gt; 'oneToMany',             'owner' =&gt; 'fairy',             'items' =&gt; 'flower'         )     ) )));   \/\/\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0447\u0435\u043a $connection = $database-&gt;get('default');  $connection-&gt;execute('     CREATE TABLE fairies (       id INTEGER PRIMARY KEY,       name VARCHAR(255)     ) ');  $connection-&gt;execute('     CREATE TABLE flowers (       id INTEGER PRIMARY KEY,       name VARCHAR(255),       fairy_id INTEGER     ) ');  \/\/\u041c\u043e\u0434\u0435\u043b\u0435\u0439 \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \/\/\u0418\u0445 \u0437\u0430\u043c\u0435\u043d\u044f\u044e\u0442 Repositories, Entities \u0438 Query  \/* \u041c\u044b \u0432\u0441\u0435 \u043d\u0435\u043d\u0430\u0432\u0438\u0434\u0438\u043c \u043a\u043e\u0433\u0434\u0430 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0442\u0430\u043a\u0436\u0435 \u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c\u0438: $fairy-&gt;name = 'Trixie'; $fairy-&gt;save(); $fairy-&gt;where('name', 'Stella')-&gt;find(); *\/  \/\/\u0420\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0438 \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0434\u043b\u044f \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0442\u0430\u0431\u043b\u0438\u0447\u0435\u043a $fairyRepository = $orm-&gt;get('fairy'); $flowerRepository = $orm-&gt;get('flower');  \/\/\u042d\u0442\u043e \u0432\u0441\u0435 \u0431\u044b\u043b\u0430 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \/\/\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c  \/\/\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0444\u0435\u0439  $trixie = $fairyRepository-&gt;create(); $trixie-&gt;name = 'Trixie'; $trixie-&gt;save();  \/\/\u0412\u0435\u0440\u0441\u0438\u044f \u043f\u043e\u043a\u043e\u0440\u043e\u0447\u0435 $fairyRepository     -&gt;create(array('name' =&gt; 'Stella'))         -&gt;save();  \/\/\u0410 \u0435\u0449\u0435 \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f \u0446\u0432\u0435\u0442\u043a\u0438  foreach(array('Red', 'Yellow', 'Green', 'Purple') as $name) {     $flowerRepository         -&gt;create(array('name' =&gt; $name))             -&gt;save(); }   \/\/\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c Query \/\/\u0430\u043d\u0430\u043b\u043e\u0433 WHERE `id` &gt; 1 AND ( `name` = 'Green' OR `name` = 'Red') $green = $flowerRepository-&gt;query()             -&gt;where('id', '&gt;', 1)             -&gt;startAndWhereGroup()                 -&gt;where('name', 'Green')                 -&gt;or('name', 'Red')             -&gt;endGroup()             -&gt;findOne();  \/\/\u0438\u043b\u0438 \u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u0435\u0435 $green = $flowerRepository-&gt;query()             -&gt;where('id', '&gt;', 1)             -&gt;and(function($q){                   $q                       -&gt;where('name', 'Green')                       -&gt;or('name', 'Red')              })             -&gt;findOne();  \/\/\u0421\u0432\u044f\u0437\u0438 \/\/\u041a\u0430\u0436\u0434\u0430\u044f \u0441\u0432\u044f\u0437\u044c \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 \u0432 \u0421\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0438 \u0417\u0430\u043f\u0440\u043e\u0441\u044b \/\/\u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e 'flowers' \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043c\u0435\u0442\u043e\u0434\u044b add(), remove() \u0438 removeAll() \/\/\u042d\u0442\u043e \u043d\u0430\u043c\u043d\u043e\u0433\u043e \u0443\u0434\u043e\u0431\u043d\u0435\u0435 \u0447\u0435\u043c \u043c\u0435\u0442\u043e\u0434\u044b addFlower(), removeFlower() \u0438 removeAllFlowers() \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u0435 $trixie-&gt;flowers-&gt;add($green);  \/\/\u041f\u0440\u0438 \u0441\u0432\u044f\u0437\u044b\u0432\u0430\u043d\u0438\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043a\u0435\u0448\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0441\u0440\u0430\u0437\u0443 \u0432 \u043e\u0431\u0435 \u0441\u0442\u043e\u0440\u043e\u043d\u044b \/\/\u0447\u0442\u043e\u0431\u044b \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a \u0431\u0430\u0437\u0435 \/\/\u0412 \u0434\u0430\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u043a\u0430\u0436\u0435\u0442\u0441\u044f \u043d\u0430 \u0442\u0430\u043a\u0438\u043c \u0443\u0436 \u0432\u0430\u0436\u043d\u044b\u043c, \u0442\u0430\u043a \u043a\u0430\u043a \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f \u0442\u0430\u043a\u043e\u0433\u043e \u044d\u0444\u0444\u0435\u043a\u0442\u0430 \/\/\u0434\u043b\u044f oneToMany \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e. \u041d\u043e \u0434\u043b\u044f manyToMany \u043e\u043d\u043e \u0442\u043e\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c assert($green-&gt;fairy() == $trixie);  \/\/\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0441\u0432\u044f\u0437\u0430\u0442\u044c \u0432\u0441\u0435 \u0446\u0432\u0435\u0442\u044b \u043a\u0440\u043e\u043c\u0435 Green c \u0444\u0435\u0435\u0439 Stella \/\/\u0418 \u0443\u043b\u043e\u0436\u0438\u0442\u044c\u0441\u044f \u0432 \u043e\u0434\u0438\u043d \u0437\u0430\u043f\u0440\u043e\u0441  \/\/\u0417\u0430\u0434\u0430\u0434\u0438\u043c \u0437\u0430\u043f\u0440\u043e\u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0448\u0435\u043b \u0431\u044b \u0421\u0442\u0435\u043b\u043b\u0443 $stellaQuery = $fairyRepository-&gt;query()                     -&gt;where('name', 'Stella');  \/\/\u0418 \u0437\u0430\u043f\u0440\u043e\u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0439\u0434\u0435\u0442 \u0446\u0432\u0435\u0442\u044b $allExceptGreen = $flowerRepository-&gt;query()                     -&gt;whereNot('name', 'Green');  \/\/\u0418 \u0442\u0435\u043f\u0435\u0440\u044c \u043c\u0430\u0433\u0438\u044f $stellaQuery-&gt;flowers-&gt;add($allExceptGreen);   \/\/\u0422\u0430\u043a\u0436\u0435 Query \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0431\u0435\u0437 \u0432\u044b\u0431\u043e\u0440\u043a\u0438 \/\/\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043f\u0435\u0440\u0435\u0438\u043c\u0435\u043d\u0443\u0435\u043c \u0446\u0432\u0435\u0442\u043e\u043a Purple \u0432 Blue $flowerRepository-&gt;query()     -&gt;where('name', 'Purple')     -&gt;update(array(         'name' =&gt; 'Blue'     ));  \/\/\u041c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0444\u0435\u044e \u0443 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0435\u0441\u0442\u044c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u0446\u0432\u0435\u0442\u043e\u043a: $trixie = $fairyRepository-&gt;query()                     -&gt;relatedTo('flowers', $green)                     -&gt;findOne();  \/\/\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0439\u0434\u0435\u043c \u0432\u0441\u0435\u0445 \u0444\u0435\u0439 \u0443 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0435\u0441\u0442\u044c \u0445\u043e\u0442\u044f \u0431\u044b \u043e\u0434\u0438\u043d \u0446\u0432\u0435\u0442\u043e\u043a \/\/\u0418 \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0434\u0433\u0440\u0443\u0437\u0438\u043c \u0432\u0441\u0435 \u0438\u0445 \u0446\u0432\u0435\u0442\u043a\u0438 $fairies = $fairyRepository-&gt;query()                     -&gt;relatedTo('flowers')                     -&gt;find(array('flowers')); \/\/\u0442\u0430\u043a \u0437\u0430\u0434\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0435\u043b\u043e\u0443\u0434\u0438\u043d\u0433 \u0441\u0432\u044f\u0437\u0435\u0439  \/\/\u0418 \u0432\u044b\u0432\u0435\u0434\u0435\u043c \u0438\u0445 \u043a\u0430\u043a \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \/\/\u0423\u0434\u043e\u0431\u043d\u043e \u0434\u043b\u044f json_encode() print_r($fairies-&gt;asArray(true));   \/\/\u0411\u043e\u043b\u044c\u0448\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u043f\u043e\u0442\u043e\u043c =) <\/code><\/pre>\n<p>  \u041f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u044d\u0442\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0443 \u0441\u0435\u0431\u044f \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e:<\/p>\n<pre><code class=\"bash\">git clone https:\/\/github.com\/phpixie\/orm cd orm\/examples   #\u0435\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u0435\u0449\u0435 \u043d\u0435\u0442 \u041a\u043e\u043c\u043f\u043e\u0437\u0435\u0440\u0430 curl -sS https:\/\/getcomposer.org\/installer | php   php composer.phar install php quickstart.php <\/code><\/pre>\n<p>  \u042d\u0442\u0430 ORM \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043b\u0430\u0441\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u0433\u043e\u0434\u0430 \u0438 \u043d\u0430\u043c \u043e\u0447\u0435\u043d\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b \u0432\u0441\u0435 \u0432\u0430\u0448\u044b \u0432\u043e\u043f\u0440\u043e\u0441\u044b \u0438 \u0437\u0430\u043c\u0435\u0447\u0430\u043d\u0438\u044f, \u043e\u0447\u0435\u043d\u044c \u0436\u0434\u0435\u043c \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u0432. \u0410 \u0435\u0441\u043b\u0438 \u0432\u0430\u043c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0443\u0437\u043d\u0430\u0442\u044c \u043e \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u0445 \u0438 \u0441\u0430\u043c\u043e\u043c \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0435 \u0442\u043e \u043d\u0435 \u0437\u0430\u0431\u0443\u0434\u044c\u0442\u0435 \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0442\u0432\u0438\u0442\u0442\u0435\u0440 <a href=\"https:\/\/twitter.com\/phpixie\">@phpixie<\/a>      \t<\/p>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/252305\/\"> http:\/\/habrahabr.ru\/post\/252305\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>     \t<img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/a9e\/60d\/e1d\/a9e60de1db7f9c18a643766e8aea6f4e.png\" alt=\"image\" align=\"right\"\/> \u0423\u0436\u0435 \u0437\u0430\u043a\u043e\u043d\u0447\u0435\u043d \u0434\u043e\u043b\u0433\u043e\u043e\u0431\u0435\u0449\u0430\u043d\u043d\u0430\u044f \u0442\u0440\u0435\u0442\u044c\u044f \u0432\u0435\u0440\u0441\u0438\u044f <a href=\"http:\/\/phpixie.com\">PHPixie<\/a> ORM \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430. \u041e\u043d \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043d\u0435\u0437\u0430\u0432\u0438\u0441\u0438\u043c \u043e\u0442 \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430 \u0438 \u043c\u043e\u0436\u0435\u0442 \u0441\u043f\u043e\u043a\u043e\u0439\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u0430\u043c \u043f\u043e \u0441\u0435\u0431\u0435. \u0412 \u0441\u0432\u044f\u0437\u0438 \u0441 \u044d\u0442\u0438\u043c, \u043f\u043e\u043a\u0430 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0435\u0442\u0441\u044f \u0440\u0430\u0431\u043e\u0442\u0430 \u043d\u0430\u0434 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430\u043c\u0438 \u0438 \u043f\u0438\u0448\u0435\u0442\u0441\u044f \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044f, \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u0441\u043e\u0441\u0442\u0430\u0432\u0438\u043b\u0438 <a href=\"https:\/\/github.com\/PHPixie\/ORM\/blob\/master\/examples\/quickstart.php\">\u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b<\/a> \u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0443\u0436\u0435 \u043d\u0430\u0447\u0430\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u041e\u0420\u041c. \u041d\u0438\u0436\u0435 \u044f \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044e \u0435\u0433\u043e \u043f\u0435\u0440\u0435\u0432\u043e\u0434 \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u044e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0432\u0435\u0449\u0435\u0439 \u043e\u0442 \u0441\u0435\u0431\u044f, \u043d\u043e \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0447\u0435\u043c \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u043c \u043f\u043e\u0440\u0430\u0434\u0443\u0435\u0442 \u043d\u0430\u0441 \u044d\u0442\u0430 \u0432\u0435\u0440\u0441\u0438\u044f:  <\/p>\n<ul>\n<li>\u0411\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e ORM \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 Model \u043a\u043b\u0430\u0441\u0441\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u043a\u0430\u043a \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0442\u0430\u043a \u0438 \u0434\u043b\u044f \u0440\u0435\u043f\u0440\u0435\u0437\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0441\u0430\u043c\u044b\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0432 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0442\u0430\u043a \u0434\u0435\u043b\u0430\u044e\u0442 Kohana \u0438 Laravel. PHPixie \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u043b\u0430 \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0430 Repository, Entity \u0438 Query, \u043a\u0430\u0436\u0434\u0430\u044f \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0438\u043c\u0435\u0435\u0442 \u0441\u0442\u0440\u043e\u0433\u043e \u0441\u0432\u043e\u0435 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435.<\/li>\n<li>\u041a\u0440\u043e\u043c\u0435 SQL \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 (SQLite, PostgreSQL, MySQL) \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0442\u0430\u043a\u0436\u0435 Mongo. \u0412\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u0432\u044f\u0437\u0430\u0442\u044c \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f\u043c\u0438 \u043c\u043e\u0434\u0435\u043b\u0438 \u0441 SQL \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438 \u0445\u0440\u0430\u043d\u044f\u0449\u0438\u043c\u0438\u0441\u044f \u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f\u0445 Mongo.<\/li>\n<li>\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c \u0441\u0432\u044f\u0437\u0438 \u043c\u0435\u0436\u0434\u0443 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0431\u0430\u0437\u0430\u043c\u0438 ( \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u043c\u0435\u0436\u0434\u0443 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c\u0438 \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u0431\u0430\u0437\u0430\u0445 \u0432 MySQL ) \u043c\u043d\u043e\u0433\u043e ORM \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0432\u043c\u0435\u0441\u0442\u043e join-\u043e\u0432 \u0438 \u0441\u0443\u0431\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432. PHPixie \u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0441\u0443\u0431\u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0432\u0441\u0435\u0433\u0434\u0430 \u0433\u0434\u0435 \u044d\u0442\u043e \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e.<\/li>\n<li>\u041f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u044b\u0445 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439 \u0432 Mongo<\/li>\n<li><a href=\"http:\/\/phpixie.com\/coverage\/orm\/ORM\/index.html\">\u041d\u0430 97% \u043f\u043e\u043a\u0440\u044b\u0442\u0430 \u044e\u043d\u0438\u0442 \u0442\u0435\u0441\u0442\u0430\u043c\u0438<\/a> ( \u043f\u043b\u0430\u043d\u0438\u0440\u0443\u0435\u0442\u0441\u044f 100% \u0434\u043e \u043a\u043e\u043d\u0446\u0430 \u044d\u0442\u043e\u0439 \u043d\u0435\u0434\u0435\u043b\u0438), \u0438 \u0435\u0449\u0435 \u043d\u0430 75% \u0444\u0443\u043d\u043a\u0446\u044b\u043e\u043d\u0430\u043b\u043d\u044b\u043c\u0438 \u0442\u0435\u0441\u0442\u0430\u043c\u0438. <\/li>\n<li>\u042d\u0444\u0444\u0435\u043a\u0442\u044b\u0432\u043d\u043e\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 Query \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c \u0447\u0438\u0441\u043b\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a \u0431\u0430\u0437\u0435. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0432\u0430\u043c \u043d\u0430\u0434\u043e \u0441\u0432\u044f\u0437\u0430\u0442\u044c \u0432\u0441\u0435 \u0442\u043e\u043f\u0438\u043a\u0438 \u0430\u0432\u0442\u043e\u0440\u0430 \u0441 \u043a\u0430\u043a\u0438\u043c\u0438-\u0442\u043e \u0442\u0435\u0433\u0430\u043c\u0438. \u0412 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u041e\u0420\u041c \u0432\u0430\u043c \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u0439\u0442\u0438 \u0442\u043e\u043f\u0438\u043a\u0438, \u043f\u043e\u0442\u043e\u043c \u0442\u0435\u0433\u0438 \u0438 \u0442\u043e\u0433\u0434\u0430 \u0441\u0432\u044f\u0437\u0430\u0442\u044c \u0438\u0445 ( 3 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043a \u0411\u0414 ). PHPixie \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0437\u0430 \u043e\u0434\u0438\u043d \u0437\u0430\u043f\u0440\u043e\u0441. \u041a\u0441\u0442\u0430\u0442\u0438 \u043f\u0440\u0438\u043c\u0435\u0440 \u044d\u0442\u043e\u0433\u043e \u0435\u0441\u0442\u044c \u0432 \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u0435 \u0441\u043d\u0438\u0437\u0443<\/li>\n<\/ul>\n<p>  \u041d\u0430\u0434\u0435\u044e\u0441\u044c \u044f \u0441\u043c\u043e\u0433 \u0432\u0430\u0441 \u0437\u0430\u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043e\u0432\u0430\u0442\u044c, \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440 \u0441 \u0441\u0441\u044b\u043b\u043a\u0438 \u0432\u0432\u0435\u0440\u0445\u0443 \u0432 \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0435:  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-252531","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/252531","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=252531"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/252531\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=252531"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=252531"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=252531"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}