{"id":286360,"date":"2017-05-15T16:30:14","date_gmt":"2017-05-15T12:30:14","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=286360"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=286360","title":{"rendered":"SQL vs ORM"},"content":{"rendered":"<p><i>\u0414\u0440\u0443\u0437\u044c\u044f, \u0432\u043d\u043e\u0432\u044c \u043f\u0440\u0438\u0448\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u0430\u0432\u0442\u043e\u0440\u0441\u043a\u043e\u0439 \u043a\u043e\u043b\u043e\u043d\u043a\u0438 \u043a\u043e\u0440\u043f\u043e\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u0431\u043b\u043e\u0433\u0430 <a href=\"https:\/\/pgday.ru\/ru\/2017\/request\/registration?utm_source=habrahabr&amp;utm_medium=blog&amp;utm_campaign=varanio3\"><b>PG Day\u201917<\/b><\/a>. \u041f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u043c \u0432\u0430\u0448\u0435\u043c\u0443 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044e \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0430\u043d\u0430\u043b\u0438\u0437 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 PostgreSQL \u0438\u0437 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 ORM \u043e\u0442 <a href=\"https:\/\/habrahabr.ru\/users\/varanio\/\" class=\"user_link\">varanio<\/a>.<\/i><\/p>\n<p>  <img decoding=\"async\" align=\"left\" src=\"https:\/\/habrastorage.org\/web\/173\/81a\/dc8\/17381adc847c42b5bfcdba54ac2c2b80.png\"\/>  <\/p>\n<p>ORM (Object-Relational Mapping), \u043f\u043e \u0438\u0434\u0435\u0435, \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c \u043d\u0430\u0441 \u043e\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f SQL \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438, \u0432 \u0438\u0434\u0435\u0430\u043b\u0435, \u0432\u043e\u043e\u0431\u0449\u0435 \u0430\u0431\u0441\u0442\u0440\u0430\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0442 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 (\u043e\u0442 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445), \u0447\u0442\u043e\u0431\u044b \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043a\u043b\u0430\u0441\u0441\u0430\u043c\u0438, \u0432 \u0442\u043e\u0439 \u0438\u043b\u0438 \u0438\u043d\u043e\u0439 \u0441\u0442\u0435\u043f\u0435\u043d\u0438 \u0432\u044b\u0440\u0430\u0436\u0430\u044e\u0449\u0438\u043c\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0438, \u043d\u0435 \u0437\u0430\u0434\u0430\u0432\u0430\u044f\u0441\u044c \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u043c, \u0432 \u043a\u0430\u043a\u0438\u0445 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445 \u0432\u0441\u0451 \u044d\u0442\u043e \u043f\u043e \u0444\u0430\u043a\u0442\u0443 \u043b\u0435\u0436\u0438\u0442.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u044d\u0442\u043e \u0443\u0434\u0430\u0435\u0442\u0441\u044f \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u043c \u043d\u0430 PHP. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u0438\u043f\u0438\u0447\u043d\u044b\u0445 \u043a\u0435\u0439\u0441\u043e\u0432 \u0438 \u0441\u0440\u0430\u0432\u043d\u0438\u043c ORM \u0441 \u0433\u043e\u043b\u044b\u043c SQL, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u043c \u0432\u0440\u0443\u0447\u043d\u0443\u044e.<\/p>\n<p><a name=\"habracut\"><\/a>  <\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0432\u043e\u0437\u044c\u043c\u0435\u043c \u0434\u0432\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b: \u043a\u043d\u0438\u0433\u0438 \u0438 \u0430\u0432\u0442\u043e\u0440\u044b \u043a\u043d\u0438\u0433, \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u043c\u043d\u043e\u0433\u0438\u0435-\u043a\u043e-\u043c\u043d\u043e\u0433\u0438\u043c (\u0443 \u043a\u043d\u0438\u0433 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u0430\u0432\u0442\u043e\u0440\u043e\u0432, \u0443 \u0430\u0432\u0442\u043e\u0440\u043e\u0432 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043c\u043d\u043e\u0433\u043e \u043a\u043d\u0438\u0433). \u0422.\u0435. \u0432 \u0431\u0430\u0437\u0435 \u044d\u0442\u043e \u0431\u0443\u0434\u0443\u0442 books, authors \u0438 \u0441\u0432\u044f\u0437\u0443\u044e\u0449\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 author_book:<\/p>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0412\u043e\u0442 \u0441\u0445\u0435\u043c\u0430<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"sql\">CREATE TABLE authors (    id bigserial,    name varchar(1000) not null,    primary key(id) );  CREATE TABLE books (    id bigserial,    name VARCHAR (1000) not null,    text text not null,    PRIMARY KEY (id) );  CREATE TABLE author_book (    author_id bigint REFERENCES authors(id),    book_id bigint REFERENCES books(id),    PRIMARY key(author_id, book_id) ); <\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<p>\u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043a\u0435\u0439\u0441\u043e\u0432 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f.<\/p>\n<p>  <\/p>\n<h2>\u041a\u0435\u0439\u0441 1. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0437\u0430\u043f\u0438\u0441\u0435\u0439<\/h2>\n<p>  <\/p>\n<p>\u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0430\u0432\u0442\u043e\u0440\u043e\u0432 \u0438 \u043a\u043d\u0438\u0433.<\/p>\n<p>  <\/p>\n<h3 id=\"golyy-sql\">\u0413\u043e\u043b\u044b\u0439 SQL<\/h3>\n<p>  <\/p>\n<p>\u041d\u0443, \u0442\u0443\u0442 \u0432\u0441\u0451 \u043f\u0440\u043e\u0441\u0442\u043e \u0438 \u043f\u0440\u044f\u043c\u043e\u043b\u0438\u043d\u0435\u0439\u043d\u043e:<\/p>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0413\u043e\u043b\u044b\u0439 SQL<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"php\">    $stmt = $pdo-&gt;prepare(         &quot;INSERT INTO books (name, text) VALUES (:name, :text) RETURNING id&quot;     );     $stmt-&gt;execute(         [':name' =&gt; '\u041a\u043d\u0438\u0433\u0430', ':text' =&gt; '\u0422\u0435\u043a\u0441\u0442']     );     $bookId = $stmt-&gt;fetchColumn();      $stmt = $pdo-&gt;prepare(         &quot;INSERT INTO authors (name) VALUES (:name) RETURNING id&quot;     );     $stmt-&gt;execute(         [':name' =&gt; '\u0410\u0432\u0442\u043e\u0440']     );     $authorId = $stmt-&gt;fetchColumn();      $pdo-&gt;prepare(         &quot;INSERT INTO author_book (book_id, author_id) VALUES (:book_id, :author_id)&quot;     )-&gt;execute(         [':book_id' =&gt; $bookId, ':author_id' =&gt; $authorId]     );<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<p>\u041c\u043d\u043e\u0433\u043e\u0432\u0430\u0442\u043e \u043f\u0438\u0441\u0430\u043d\u0438\u043d\u044b. \u041c\u043e\u0436\u043d\u043e \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u044f\u043c \u0441\u043e\u0432\u0441\u0435\u043c \u0433\u043e\u043b\u044b\u0439 PDO, \u0430 \u0432\u0437\u044f\u0442\u044c \u0447\u0442\u043e-\u043d\u0438\u0431\u0443\u0434\u044c \u0447\u0443\u0442\u044c \u043f\u043e\u043b\u0430\u043a\u043e\u043d\u0438\u0447\u043d\u0435\u0435, \u043a\u0430\u043a\u0443\u044e-\u043d\u0438\u0431\u0443\u0434\u044c \u043b\u0435\u0433\u043a\u0443\u044e \u043e\u0431\u0435\u0440\u0442\u043a\u0443. \u041d\u043e \u0432 \u043b\u044e\u0431\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043d\u0430\u0434\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0438 \u0437\u043d\u0430\u0442\u044c \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 SQL.<\/p>\n<p>  <\/p>\n<h3 id=\"laravel-eloquent-sql\">Laravel (Eloquent SQL)<\/h3>\n<p>  <\/p>\n<p>\u0412 Laravel \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f ORM \u043f\u043e\u0434 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c Eloquent. Eloquent \u2014 \u044d\u0442\u043e, \u043f\u043e \u0441\u0443\u0442\u0438, ActiveRecord, \u0442.\u0435. \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0446 \u043d\u0430 \u043d\u0435\u043a\u0438\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0438\u043c \u043a\u043b\u0430\u0441\u0441\u044b (&quot;\u043c\u043e\u0434\u0435\u043b\u0438&quot;), \u043f\u0440\u0438\u0447\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u044c \u0441\u0430\u043c\u0430 \u0443\u043c\u0435\u0435\u0442 \u0441\u0435\u0431\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c.<\/p>\n<p>  <\/p>\n<p>\u0418\u0442\u0430\u043a, \u0434\u0435\u043b\u0430\u0435\u043c \u0434\u0432\u0435 \u043c\u043e\u0434\u0435\u043b\u0438. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0434\u0430\u0436\u0435 \u0438\u043c\u0435\u043d\u0430 \u0442\u0430\u0431\u043b\u0438\u0446 \u043d\u0438\u0433\u0434\u0435 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0435 \u043d\u0430\u0434\u043e, \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u043d\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043a\u0430\u043a \u043a\u043b\u0430\u0441\u0441\u044b. \u041d\u0430\u0434\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c $timestamps = false, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u043b\u043e \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u0440\u0435\u043c\u044f \u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043b\u0430\u0441\u0441\u044b \u043c\u043e\u0434\u0435\u043b\u0435\u0439 Eloquent<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"php\"> namespace App;   use Illuminate\\Database\\Eloquent\\Model;   class Book extends Model  {      public $timestamps = false;       public function authors()      {          return $this-&gt;belongsToMany(Author::class);      }  }<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"php\">namespace App;  use Illuminate\\Database\\Eloquent\\Model;  class Author extends Model {     public $timestamps = false;      public function books()     {         return $this-&gt;belongsToMany(Books::class);     } }<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0432\u0438\u0434\u043d\u043e, \u043c\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u0442\u043e \u043e\u043f\u0438\u0441\u0430\u043b\u0438 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 many-to-many \u0431\u0443\u043a\u0432\u0430\u043b\u044c\u043d\u043e \u043f\u0430\u0440\u043e\u0439 \u0441\u0442\u0440\u043e\u043a \u043a\u043e\u0434\u0430. \u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0432 \u0431\u0430\u0437\u0435 \u0438 \u0441\u0432\u044f\u0437\u044c \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438 \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">$book = new \\App\\Book; $book-&gt;name = '\u041a\u043d\u0438\u0433\u0430'; $book-&gt;text = '\u0422\u0435\u043a\u0441\u0442'; $book-&gt;save();  $author = new \\App\\Author; $author-&gt;name = '\u0410\u0432\u0442\u043e\u0440'; $author-&gt;save();  \/\/ \u0434\u0435\u043b\u0430\u0435\u043c \u0441\u0432\u044f\u0437\u044c $book-&gt;authors()-&gt;save($author);<\/code><\/pre>\n<p>  <\/p>\n<p>\u0418\u043b\u0438 \u0441\u043f\u0438\u0441\u043a\u043e\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">$book = \\App\\Book::create(['name' =&gt; '\u041a\u043d\u0438\u0433\u0430', 'text' =&gt; '\u0422\u0435\u043a\u0441\u0442']); $author = \\App\\Author::create(['name' =&gt; '\u0410\u0432\u0442\u043e\u0440']); $book-&gt;authors()-&gt;save($author);<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0430\u043a, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043f\u043e\u043f\u0440\u0438\u044f\u0442\u043d\u0435\u0435, \u0447\u0435\u043c \u0432\u043e\u0437\u0438\u0442\u044c\u0441\u044f \u0441 SQL, \u0438 \u0434\u0430\u0436\u0435 \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u0441\u0432\u044f\u0437\u043e\u0447\u043d\u0443\u044e \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0434\u0435\u043b\u0430\u0435\u0442\u0441\u044f \u043e\u0447\u0435\u043d\u044c \u043b\u0435\u0433\u043a\u043e.<\/p>\n<p>  <\/p>\n<h3 id=\"symfony-doctrine-orm\">Symfony (Doctrine ORM)<\/h3>\n<p>  <\/p>\n<p>\u0412 \u0434\u043e\u043a\u0442\u0440\u0438\u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043f\u043e\u0434\u0445\u043e\u0434 DataMapper. \u041f\u043e \u0443\u0432\u0435\u0440\u0435\u043d\u0438\u044f\u043c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438, \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0438 \u043e\u0442\u0434\u0435\u043b\u0435\u043d\u044b \u043e\u0442 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f. \u0417\u0434\u0435\u0441\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0442\u0441\u044f \u0438\u0437 \u0420\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u044f (Repository), \u0442.\u0435. \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c \u043d\u0435 \u0437\u043d\u0430\u0435\u0442 \u043a\u0430\u043a \u0441\u0435\u0431\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c, \u044d\u0442\u043e \u0437\u043d\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e Repository, \u0430 \u0434\u043b\u044f \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f EntityManager.<\/p>\n<p>  <\/p>\n<p>\u0421\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u044b \u0438\u0437 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0442\u0430\u0431\u043b\u0438\u0446 \u043c\u043e\u0436\u043d\u043e \u043e\u0434\u043d\u0438\u043c \u0434\u0432\u0438\u0436\u0435\u043d\u0438\u0435\u043c: <\/p>\n<p>  <\/p>\n<pre><code class=\"bash\">bin\/console doctrine:mapping:import --force AppBundle yml bin\/console doctrine:generate:entities AppBundle<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u0435\u0440\u0432\u0430\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u0441\u043e\u0437\u0434\u0430\u0441\u0442 yml-\u0444\u0430\u0439\u043b\u044b \u0434\u043b\u044f \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439, \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0438\u0435 \u0442\u0438\u043f\u044b \u043f\u043e\u043b\u0435\u0439 \u0432 \u0431\u0430\u0437\u0435, \u0432\u0437\u0430\u0438\u043c\u043e\u0441\u0432\u044f\u0437\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, many-to-many) \u0438 \u0442.\u0434. \u0412\u0442\u043e\u0440\u0430\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u0441\u043e\u0437\u0434\u0430\u0441\u0442 \u043a\u043b\u0430\u0441\u0441\u044b \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439. <\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u044f\u043c\u043e \u0441\u043a\u0430\u0436\u0435\u043c, yml \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438\u0441\u044c \u043d\u0435\u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u0435, \u0438 \u043e\u043d\u0438 \u043d\u0430\u0431\u0438\u0442\u044b \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0441\u0442\u044f\u043c\u0438 \u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 \u0442\u0430\u0431\u043b\u0438\u0446 \u0438 \u0438\u0445 \u0441\u0432\u044f\u0437\u044f\u0445. \u0412\u043e\u043e\u0431\u0449\u0435, \u043c\u043e\u0436\u043d\u043e \u043e\u0431\u043e\u0439\u0442\u0438\u0441\u044c \u0438 \u0431\u0435\u0437 yml, \u0432\u0441\u0451 \u0434\u0435\u043b\u0430\u044f \u0432 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432. \u041d\u043e \u043a\u043e\u0433\u0434\u0430 \u043a\u043b\u0430\u0441\u0441\u044b \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0435\u0439 \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u043e\u0442\u0434\u0435\u043b\u0435\u043d\u044b \u043e\u0442 \u0431\u0430\u0437\u044b, \u044d\u0442\u043e \u0431\u043e\u043b\u044c\u0448\u0435 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u0438 DDD.<\/p>\n<p>  <\/p>\n<p>\u0417\u0430\u0442\u043e \u0441\u0430\u043c\u0438 \u043a\u043b\u0430\u0441\u0441\u044b-\u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438 \u0443 \u043d\u0430\u0441 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438\u0441\u044c \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u0435, \u0442.\u0435. POJO (plain old php object):<\/p>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043b\u0430\u0441\u0441\u044b-\u0441\u0443\u0449\u043d\u043e\u0441\u0442\u0438<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"php\">namespace AppBundle\\Entity;  \/**  * Authors  *\/ class Authors {     \/**      * @var integer      *\/     private $id;      \/**      * @var string      *\/     private $name;      \/**      * @var  \\Doctrine\\Common\\Collections\\Collection      *\/     private $book;      \/**      * Constructor      *\/     public function __construct()     {         $this-&gt;book = new \\Doctrine\\Common\\Collections\\ArrayCollection();     }      \/**      * Get id      *      * @return integer      *\/     public function getId()     {         return $this-&gt;id;     }      \/**      * Set name      *      * @param string $name      *      * @return Authors      *\/     public function setName($name)     {         $this-&gt;name = $name;          return $this;     }      \/**      * Get name      *      * @return string      *\/     public function getName()     {         return $this-&gt;name;     }      \/**      * Add book      *      * @param \\AppBundle\\Entity\\Books $book      *      * @return Authors      *\/     public function addBook(\\AppBundle\\Entity\\Books $book)     {         $this-&gt;book[] = $book;          return $this;     }      \/**      * Remove book      *      * @param \\AppBundle\\Entity\\Books $book      *\/     public function removeBook(\\AppBundle\\Entity\\Books $book)     {         $this-&gt;book-&gt;removeElement($book);     }      \/**      * Get book      *      * @return \\Doctrine\\Common\\Collections\\Collection      *\/     public function getBook()     {         return $this-&gt;book;     } } <\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"php\">namespace AppBundle\\Entity;  \/**  * Books  *\/ class Books {     \/**      * @var integer      *\/     private $id;      \/**      * @var string      *\/     private $name;      \/**      * @var string      *\/     private $text;      \/**      * @var \\Doctrine\\Common\\Collections\\Collection      *\/     private $author;      \/**      * Constructor      *\/     public function __construct()     {         $this-&gt;author = new \\Doctrine\\Common\\Collections\\ArrayCollection();     }      \/**      * Get id      *      * @return integer      *\/     public function getId()     {         return $this-&gt;id;     }      \/**      * Set name      *      * @param string $name      *      * @return Books      *\/     public function setName($name)     {         $this-&gt;name = $name;          return $this;     }      \/**      * Get name      *      * @return string      *\/     public function getName()     {         return $this-&gt;name;     }      \/**      * Set text      *      * @param string $text      *      * @return Books      *\/     public function setText($text)     {         $this-&gt;text = $text;          return $this;     }      \/**      * Get text      *      * @return string      *\/     public function getText()     {         return $this-&gt;text;     }      \/**      * Add author      *      * @param \\AppBundle\\Entity\\Authors $author      *      * @return Books      *\/     public function addAuthor(\\AppBundle\\Entity\\Authors $author)     {         $this-&gt;author[] = $author;          return $this;     }      \/**      * Remove author      *      * @param \\AppBundle\\Entity\\Authors $author      *\/     public function removeAuthor(\\AppBundle\\Entity\\Authors $author)     {         $this-&gt;author-&gt;removeElement($author);     }      \/**      * Get author      *      * @return \\Doctrine\\Common\\Collections\\Collection      *\/     public function getAuthor()     {         return $this-&gt;author;     } }<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c. \u041f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">$em = $this-&gt;getDoctrine()-&gt;getManager();  $author = new Authors(); $author-&gt;setName(&quot;\u0410\u0432\u0442\u043e\u0440&quot;);  $book =  new Books(); $book-&gt;setName(&quot;\u041a\u043d\u0438\u0433\u0430&quot;); $book-&gt;setText(&quot;\u0422\u0435\u043a\u0441\u0442&quot;);  $book-&gt;addAuthor($author); $author-&gt;addBook($book);  $em-&gt;persist($book); $em-&gt;persist($author); $em-&gt;flush();<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"vyvod\">\u0412\u044b\u0432\u043e\u0434<\/h3>\n<p>  <\/p>\n<p>\u0412 \u0446\u0435\u043b\u043e\u043c, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 ORM \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0442\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c, \u0447\u0435\u043c \u0447\u0438\u0441\u0442\u044b\u0439 SQL. \u041c\u0435\u0442\u043e\u0434\u044b setName \u0438 \u0442.\u0434. \u0432 \u043a\u043e\u0434\u0435 \u0447\u0438\u0442\u0430\u044e\u0442\u0441\u044f \u043b\u0443\u0447\u0448\u0435, \u0447\u0435\u043c SQL-\u0437\u0430\u043f\u0440\u043e\u0441. \u041d\u0435\u0442 \u0436\u0435\u0441\u0442\u043a\u043e\u0439 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0411\u0414.<\/p>\n<p>  <\/p>\n<h2>\u041a\u0435\u0439\u0441 2. \u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u043a\u043d\u0438\u0433\u0438<\/h2>\n<p>  <\/p>\n<h3 id=\"golyy-sql-1\">\u0413\u043e\u043b\u044b\u0439 SQL<\/h3>\n<p>  <\/p>\n<pre><code class=\"php\">$stmt = $pdo-&gt;prepare('UPDATE books SET name=:name WHERE id=:id'); $stmt-&gt;execute([     ':name' =&gt; '\u041a\u043d\u0438\u0433\u0430 2', ':id' =&gt; 1 ]);<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"laravel-eloquent\">Laravel (Eloquent)<\/h3>\n<p>  <\/p>\n<pre><code class=\"php\">$book = \\App\\Book::find(1); $book-&gt;name = '\u041a\u043d\u0438\u0433\u0430 2'; $book-&gt;save();<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"symfony\">Symfony<\/h3>\n<p>  <\/p>\n<pre><code class=\"php\">$em = $this-&gt;getDoctrine()-&gt;getManager(); $repository = $em-&gt;getRepository(Books::class); $book = $repository-&gt;find(1); $book-&gt;setName(&quot;\u041a\u043d\u0438\u0433\u0430 2&quot;); $em-&gt;persist($book);<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"vyvod-1\">\u0412\u044b\u0432\u043e\u0434<\/h3>\n<p>  <\/p>\n<p>\u041e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435 \u043a\u0430\u043a\u043e\u0433\u043e-\u0442\u043e \u043f\u043e\u043b\u044f \u0432 \u0446\u0435\u043b\u043e\u043c \u0442\u043e\u0436\u0435 \u0432\u043f\u043e\u043b\u043d\u0435 \u043c\u043e\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u0447\u0435\u0440\u0435\u0437 ORM, \u043d\u0435 \u0432\u0434\u0430\u0432\u0430\u044f\u0441\u044c \u0432 \u0434\u0435\u0442\u0430\u043b\u0438 SQL.<\/p>\n<p>  <\/p>\n<h2>\u041a\u0435\u0439\u0441 3. \u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0439 \u043a\u043d\u0438\u0433 \u0441 \u0430\u0432\u0442\u043e\u0440\u0430\u043c\u0438<\/h2>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0442\u0435\u0441\u0442\u043e\u0432 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0442\u0430\u043a\u0438\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435:<\/p>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0414\u0430\u043d\u043d\u044b\u0435<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"sql\">delete from author_book; delete from books; delete from authors;  insert into authors  (id, name)  values  (1, '\u0410\u0432\u0442\u043e\u0440 1'), (2, '\u0410\u0432\u0442\u043e\u0440 2'), (3, '\u0410\u0432\u0442\u043e\u0440 3');  insert into books  (id, name, text)  values  (1, '\u041a\u043d\u0438\u0433\u0430 1', '\u041c\u043d\u043e\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u0430 1'), (2, '\u041a\u043d\u0438\u0433\u0430 2', '\u041c\u043d\u043e\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u0430 2'), (3, '\u041a\u043d\u0438\u0433\u0430 3', '\u041c\u043d\u043e\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u0430 3');  insert into author_book  (author_id , book_id)  values    (1,1),   (1,2),   (2,2),     (3,3);<\/code><\/pre>\n<\/div>\n<\/div>\n<p>  <\/p>\n<h3 id=\"golyy-sql-2\">\u0413\u043e\u043b\u044b\u0439 SQL<\/h3>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0431\u0440\u0430\u0442\u044c \u0433\u043e\u043b\u044b\u0439 SQL \u0434\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430 \u0441\u043f\u0438\u0441\u043a\u0430 \u043a\u043d\u0438\u0433 \u0441 \u0430\u0432\u0442\u043e\u0440\u0430\u043c\u0438, \u0442\u043e \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a (\u0434\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0430\u0432\u0442\u043e\u0440\u043e\u0432 \u0445\u043e\u0442\u0438\u043c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0432 \u0432\u0438\u0434\u0435 json):<\/p>\n<p>  <\/p>\n<pre><code class=\"sql\">select    b.id as book_id,    b.name as book_name,    json_agg(a.name) as authors  from books b     inner join author_book ab       on b.id = ab.book_id    INNER join authors a        on ab.author_id = a.id GROUP BY     b.id<\/code><\/pre>\n<p>  <\/p>\n<p>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442:<\/p>\n<p>  <\/p>\n<pre><code class=\"sql\"> book_id | book_name |        authors          ---------+-----------+------------------------        1 | \u041a\u043d\u0438\u0433\u0430 1   | [&quot;\u0410\u0432\u0442\u043e\u0440 1&quot;]        3 | \u041a\u043d\u0438\u0433\u0430 3   | [&quot;\u0410\u0432\u0442\u043e\u0440 3&quot;]        2 | \u041a\u043d\u0438\u0433\u0430 2   | [&quot;\u0410\u0432\u0442\u043e\u0440 1&quot;, &quot;\u0410\u0432\u0442\u043e\u0440 2&quot;] (3 rows)<\/code><\/pre>\n<p>  <\/p>\n<h2>Laravel<\/h2>\n<p>  <\/p>\n<p>\u0421\u0434\u0435\u043b\u0430\u0435\u043c \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0432\u0442\u0443\u043f\u0443\u044e \u0438\u0437 \u043c\u0430\u043d\u0443\u0430\u043b\u043e\u0432 \u0430-\u043b\u044f &quot;Getting Started&quot;:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">    $books = \\App\\Book::all();      \/** @var $author \\App\\Author *\/     foreach ($books as $book) {         print $book-&gt;name . &quot;\\n&quot;;         foreach ($book-&gt;authors as $author) {             print $author-&gt;name . &quot;;&quot;;         }     }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u043e\u0434 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0441\u044f \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043f\u0440\u043e\u0449\u0435, \u0447\u0435\u043c \u0433\u043e\u043b\u044b\u0439 SQL. \u0412\u0441\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0438 \u043f\u043e\u043d\u044f\u0442\u043d\u043e, works like magic. \u0422\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438 \u0434\u0435\u0442\u0430\u043b\u044c\u043d\u043e\u043c \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u043d\u0438\u0438 \u043c\u0430\u0433\u0438\u044f \u0442\u0430\u043c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0444\u0438\u0433\u043e\u0432\u0430\u044f. Eloquent \u0434\u0435\u043b\u0430\u0435\u0442 \u0430\u0436 4 \u0437\u0430\u043f\u0440\u043e\u0441\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"sql\">select * from &quot;books&quot;; -- \u0438 \u0435\u0449\u0435 \u043f\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0443 \u043d\u0430 \u043a\u0430\u0436\u0434\u0443\u044e \u043a\u043d\u0438\u0433\u0443:  select     &quot;authors&quot;.*,     &quot;author_book&quot;.&quot;book_id&quot; as &quot;pivot_book_id&quot;,     &quot;author_book&quot;.&quot;author_id&quot; as &quot;pivot_author_id&quot;  from &quot;authors&quot;     inner join &quot;author_book&quot;         on &quot;authors&quot;.&quot;id&quot; = &quot;author_book&quot;.&quot;author_id&quot;  where &quot;author_book&quot;.&quot;book_id&quot; = ?<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u043e\u0433\u043e \u043d\u0435\u043d\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u043e\u0433\u043e \u0441\u0430\u0439\u0442\u0430 \u0441\u043e\u0439\u0434\u0435\u0442 \u0438 \u0442\u0430\u043a. \u041d\u043e \u0435\u0441\u043b\u0438 \u0441\u0430\u0439\u0442 \u043d\u0430\u0433\u0440\u0443\u0436\u0435\u043d \u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442 \u043c\u043d\u043e\u0433\u043e \u0441\u0442\u0440\u043e\u043a \u0438 \u0434\u0430\u043d\u043d\u044b\u0445, \u0442\u043e \u044d\u0442\u043e \u043f\u0440\u043e\u0432\u0430\u043b.<\/p>\n<p>  <\/p>\n<p>\u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 <code>select *<\/code> \u0438 <code>select authors.*<\/code>. \u0417\u0430 \u0442\u0430\u043a\u043e\u0435 \u0441\u0440\u0430\u0437\u0443 \u043f\u0430\u0440\u0442\u0431\u0438\u043b\u0435\u0442 \u043d\u0430 \u0441\u0442\u043e\u043b. \u0415\u0441\u043b\u0438 \u043a\u043d\u0438\u0433\u0438 \u0431\u0443\u0434\u0443\u0442 &quot;\u0436\u0438\u0440\u043d\u044b\u043c\u0438&quot; (&quot;\u0412\u043e\u0439\u043d\u0430 \u0438 \u041c\u0438\u0440&quot; \u0438\u043b\u0438 &quot;\u0411\u0440\u0438\u0442\u0430\u043d\u0441\u043a\u0430\u044f \u044d\u043d\u0446\u0438\u043a\u043b\u043e\u043f\u0435\u0434\u0438\u044f&quot;), \u0442\u043e \u043d\u0438 \u043a \u0447\u0435\u043c\u0443 \u0442\u044f\u043d\u0443\u0442\u044c \u0441\u0440\u0430\u0437\u0443 \u0438\u0445 \u0442\u0435\u043a\u0441\u0442, \u043a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u043f\u0438\u0441\u043e\u043a \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0439. \u041a \u0442\u043e\u043c\u0443 \u0436\u0435, \u0441\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u043f\u043e\u043b\u0435\u0439 \u043e\u0431\u044b\u0447\u043d\u043e \u0432\u0441\u0435 \u043d\u0430\u0440\u0430\u0441\u0442\u0430\u0435\u0442 \u0438 \u043d\u0430\u0440\u0430\u0441\u0442\u0430\u0435\u0442, \u0442.\u0435. \u0442\u0430\u043a\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0432\u0441\u0451 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435 \u0438 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435, \u0436\u0440\u0430\u0442\u044c \u0432\u0441\u0451 \u0431\u043e\u043b\u044c\u0448\u0435 \u0438 \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u0430\u043c\u044f\u0442\u0438. \u042f \u0443\u0436 \u043d\u0435 \u0433\u043e\u0432\u043e\u0440\u044e \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 authors.* \u0440\u0430\u0432\u043d\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0443 \u043a\u043d\u0438\u0433.<\/p>\n<p>  <\/p>\n<p>\u0427\u0442\u043e \u0442\u0443\u0442 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u043f\u0440\u0438\u043d\u044f\u0442\u044c? \u0412\u043e-\u043f\u0435\u0440\u0432\u044b\u0445, \u043c\u043e\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c, \u043a\u0430\u043a\u0438\u0435 \u043f\u043e\u043b\u044f \u0431\u0435\u0440\u0435\u043c \u0438\u0437 \u043a\u043d\u0438\u0433\u0438, \u0442.\u0435 <code>(['id', 'name'])<\/code>. \u041d\u0443, \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c with() \u0434\u043b\u044f \u0442.\u043d. &quot;eager loading&quot;. \u0418\u0442\u043e\u0433\u043e:<\/p>\n<p>  <\/p>\n<pre><code class=\"sql\">$books = \\App\\Book::with('authors')-&gt;get(['id', 'name']);<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u0442\u0430\u043b\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u0443\u0447\u0448\u0435, \u043d\u043e \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u0434\u0430\u043b\u0435\u043a\u043e \u043e\u0442 \u0438\u0434\u0435\u0430\u043b\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"sql\">select &quot;id&quot;, &quot;name&quot; from &quot;books&quot;; select    &quot;authors&quot;.*,    &quot;author_book&quot;.&quot;book_id&quot; as &quot;pivot_book_id&quot;,    &quot;author_book&quot;.&quot;author_id&quot; as &quot;pivot_author_id&quot;  from &quot;authors&quot;    inner join &quot;author_book&quot;      on &quot;authors&quot;.&quot;id&quot; = &quot;author_book&quot;.&quot;author_id&quot;  where    &quot;author_book&quot;.&quot;book_id&quot; in (?, ?, ?);<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422\u0443\u0442 \u0434\u0432\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b: authors \u0438\u0434\u0443\u0442 \u0432\u0441\u0451 \u0440\u0430\u0432\u043d\u043e \u0441\u043e \u0437\u0432\u0435\u0437\u0434\u043e\u0447\u043a\u043e\u0439. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 in() \u0441 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435\u043c \u0432\u0441\u0435\u0445 id, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u0440\u0438 \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u043e\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u043a\u043d\u0438\u0433, \u043d\u043e \u0434\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u0441\u043f\u0438\u0441\u043a\u0430 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043e\u0447\u0435\u043d\u044c \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u043e, \u043f\u043e \u043a\u0440\u0430\u0439\u043d\u0435\u0439 \u043c\u0435\u0440\u0435 \u0432 PostgreSQL. \u0425\u043e\u0442\u044f, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u0431\u044b\u0441\u0442\u0440\u0435\u0435, \u0447\u0435\u043c \u043f\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0443 \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439. \u0418 \u0441 \u044d\u0442\u0438\u043c \u0443\u0436\u0435, \u043f\u043e\u0445\u043e\u0436\u0435, \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c, \u043f\u043e \u043a\u0440\u0430\u0439\u043d\u0435\u0439 \u043c\u0435\u0440\u0435 \u044f \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043d\u0430\u0448\u0435\u043b.<\/p>\n<p>  <\/p>\n<p>\u0422\u043e\u0447\u043d\u0435\u0435, \u043f\u043e\u043c\u0438\u043c\u043e ORM \u0435\u0441\u0442\u044c \u0435\u0449\u0435 Query Builder:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">     $result = DB::table('books')          -&gt;join('author_book', 'books.id', '=', 'author_book.book_id')          -&gt;join('authors', 'author_book.author_id', '=', 'authors.id')          -&gt;select('books.id', 'books.name', 'authors.name')          -&gt;get();<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u043e \u044d\u0442\u043e, \u043f\u043e\u0432\u0442\u043e\u0440\u044f\u044e, \u043d\u0435 ORM. \u042d\u0442\u043e \u0442\u043e\u0442 \u0436\u0435 SQL, \u0442\u043e\u043b\u044c\u043a\u043e \u0432\u043c\u0435\u0441\u0442\u043e \u043f\u0440\u043e\u0431\u0435\u043b\u043e\u0432 \u0441\u0442\u0440\u0435\u043b\u043e\u0447\u043a\u0438 \u0438 \u043a\u0443\u0447\u0430 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0434\u043e \u0437\u043d\u0430\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e.<\/p>\n<p>  <\/p>\n<h3 id=\"symfony-1\">Symfony<\/h3>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0442\u043e\u0436\u0435 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u043f\u043e-\u043f\u0440\u043e\u0441\u0442\u043e\u043c\u0443:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">$doctrine = $this-&gt;getDoctrine(); $books = $doctrine     -&gt;getRepository(Books::class)     -&gt;findAll();  foreach ($books as $book) {     print $book-&gt;getName() . &quot;\\n&quot;;     foreach ($book-&gt;getAuthor() as $author) {         print $author-&gt;getName() . &quot;;&quot;;     } }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u043e\u0434 \u043f\u0435\u0440\u0432\u043e\u0439 \u043f\u043e\u043f\u044b\u0442\u043a\u0438 \u043f\u043e\u0447\u0442\u0438 \u0442\u0430\u043a\u043e\u0439 \u0436\u0435 \u043a\u0430\u043a \u0432 Laravel. SQL-\u0437\u0430\u043f\u0440\u043e\u0441\u044b, \u0432 \u043e\u0431\u0449\u0435\u043c, \u0442\u043e\u0436\u0435:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">SELECT      t0.id AS id_1,      t0.name AS name_2,      t0.text AS text_3  FROM books t0;  -- \u0438 \u0435\u0449\u0435 3 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0442\u0430\u043a\u0438\u0445: SELECT      t0.id AS id_1,      t0.name AS name_2  FROM authors t0      INNER JOIN author_book           ON t0.id = author_book.author_id  WHERE       author_book.book_id = ?<\/code><\/pre>\n<p>  <\/p>\n<p>\u0422.\u0435. \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u044b \u0432\u0441\u0435 \u043f\u043e\u043b\u044f, \u0438 \u043f\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0443 \u043d\u0430 \u043a\u0430\u0436\u0434\u0443\u044e \u043a\u043d\u0438\u0433\u0443 \u0441 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435\u043c, \u043e\u043f\u044f\u0442\u044c \u0436\u0435, \u0432\u0441\u0435\u0445 \u043f\u043e\u043b\u0435\u0439.<\/p>\n<p>  <\/p>\n<p>\u0423 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0442\u0438\u043f\u0430 findAll \u0438 \u0442.\u0434., \u043f\u043e\u0445\u043e\u0436\u0435, \u043d\u0435\u0442 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u0443\u043a\u0430\u0437\u0430\u0442\u044c, \u0447\u0442\u043e \u043c\u043d\u0435 \u043d\u0430\u0434\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u0430\u043a\u0438\u0435-\u0442\u043e \u043f\u043e\u043b\u044f \u0438 \u0441\u0440\u0430\u0437\u0443 \u043f\u0440\u0438\u0434\u0436\u043e\u0439\u043d\u0438\u0442\u044c \u0442\u0430\u043a\u0438\u0435-\u0442\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u044b. \u041d\u043e, \u0437\u0430\u0442\u043e \u0432 \u0414\u043e\u043a\u0442\u0440\u0438\u043d\u0435 \u0435\u0441\u0442\u044c SQL-\u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0439 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441 DQL, \u0430\u0431\u0441\u0442\u0440\u0430\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043e\u0442 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u0421\u0423\u0411\u0414, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043c\u043e\u0436\u043d\u043e \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f. \u041e\u043d \u043e\u043f\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043d\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c\u0438, \u0430 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044f\u043c\u0438.<\/p>\n<p>  <\/p>\n<pre><code class=\"php\"> $query = $this-&gt;getDoctrine()-&gt;getManager()-&gt;createQuery('     SELECT           partial b.{id, name}, partial a.{id, name}      FROM AppBundle\\Entity\\Books b         JOIN b.author a'  );  $books = $query-&gt;getResult(); <\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0443 \u0434\u0430, \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0442\u0438\u043f\u0430 \u0442\u043e\u0433\u043e, \u0447\u0442\u043e \u043d\u0430\u0434\u043e, \u043e\u0434\u0438\u043d \u0437\u0430\u043f\u0440\u043e\u0441, \u0441 \u043e\u0434\u043d\u0438\u043c \u043f\u043e\u043b\u0435\u043c:<\/p>\n<p>  <\/p>\n<pre><code class=\"sql\">SELECT     b0_.id AS id_0,     b0_.name AS name_1,     a1_.id AS id_2,     a1_.name AS name_3  FROM     books b0_  INNER JOIN author_book a2_     ON b0_.id = a2_.book_id  INNER JOIN authors a1_     ON a1_.id = a2_.author_id<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"vyvody\">\u0412\u044b\u0432\u043e\u0434\u044b<\/h3>\n<p>  <\/p>\n<p>\u041d\u0430 \u043c\u043e\u0439 \u0432\u0437\u0433\u043b\u044f\u0434, \u043f\u0440\u043e\u0441\u0442\u043e\u0439 SQL \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u0440\u043e\u0449\u0435 \u0438 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0435\u0435. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0432 ORM-\u043f\u043e\u0434\u0445\u043e\u0434\u0430\u0445 \u043c\u044b \u043d\u0435 \u0441\u043c\u043e\u0433\u043b\u0438 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0441\u0444\u0435\u0440\u0438\u0447\u0435\u0441\u043a\u0438 \u0430\u0431\u0441\u0442\u0440\u0430\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043e\u0442 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u043d\u0430\u043c \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u043f\u043e\u0434\u0441\u0442\u0440\u043e\u0438\u0442\u044c\u0441\u044f \u043f\u043e\u0434 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u0438\u0440.<\/p>\n<p>  <\/p>\n<p>DQL \u0432 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435 \u0441\u043e\u0439\u0434\u0435\u0442 \u043d\u0430 \u0437\u0430\u043c\u0435\u043d\u0443 SQL, \u0438 \u043e\u043d \u043d\u0435 \u043e\u0441\u043e\u0431\u043e \u043f\u0440\u0438\u0432\u044f\u0437\u0430\u043d \u043a \u0421\u0423\u0411\u0414, \u043d\u043e \u044d\u0442\u043e \u0435\u0449\u0435 \u043e\u0434\u0438\u043d \u0441\u0442\u0440\u0430\u043d\u043d\u043e\u0432\u0430\u0442\u044b\u0439 \u0441\u0438\u043d\u0442\u0430\u043a\u0441\u0438\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u0434\u043e \u0443\u0447\u0438\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e.<\/p>\n<p>  <\/p>\n<h2>\u041a\u0435\u0439\u0441 4. \u0427\u0443\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0439 UPDATE<\/h2>\n<p>  <\/p>\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u0441\u0442\u043e\u0438\u0442 \u0437\u0430\u0434\u0430\u0447\u0430 \u043e\u0431\u043d\u043e\u0432\u0438\u0442\u044c \u0434\u0432\u0443\u043c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c \u0430\u0432\u0442\u043e\u0440\u0430\u043c \u0438\u043c\u044f \u043d\u0430 &quot;\u0416\u043e\u0440\u0436&quot;. <\/p>\n<p>  <\/p>\n<h3 id=\"golyy-sql-3\">\u0433\u043e\u043b\u044b\u0439 SQL<\/h3>\n<p>  <\/p>\n<p>\u0422\u0443\u0442 \u0432\u0441\u0451 \u043f\u0440\u043e\u0441\u0442\u043e, \u0437\u0430\u043f\u0440\u043e\u0441 \u0441 \u043f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c.<\/p>\n<p>  <\/p>\n<pre><code class=\"sql\">UPDATE authors SET name = '\u0416\u043e\u0440\u0436' WHERE id in (     SELECT id     FROM authors     ORDER BY id DESC     LIMIT 2 );<\/code><\/pre>\n<p>  <\/p>\n<h3 id=\"laravel\">Laravel<\/h3>\n<p>  <\/p>\n<p>\u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u044f \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u043b \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\"> \\App\\Author::orderBy('id', 'desc')-&gt;take(2)-&gt;update([&quot;name&quot; =&gt; &quot;\u0416\u043e\u0440\u0436&quot;]);<\/code><\/pre>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0437\u0434\u043e\u0440\u043e\u0432\u043e \u0438 \u043a\u0440\u0430\u0441\u0438\u0432\u043e, \u043e\u0434\u043d\u0430\u043a\u043e \u043d\u0435 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e. \u0422\u043e\u0447\u043d\u0435\u0435 \u0441\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u043e, \u043d\u043e \u0437\u0430\u043c\u0435\u043d\u0438\u043b\u043e \u0437\u0430\u043f\u0438\u0441\u0438 \u0432\u0441\u0435\u043c \u0430\u0432\u0442\u043e\u0440\u0430\u043c, \u0430 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u0432\u0443\u043c.<\/p>\n<p>  <\/p>\n<p>\u0422\u043e\u0433\u0434\u0430, \u043f\u043e\u043a\u0443\u0440\u0438\u0432 \u043c\u0430\u043d\u0443\u0430\u043b \u0438 SO, \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0440\u043e\u0434\u0438\u0442\u044c \u0442\u0430\u043a\u0443\u044e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e:<\/p>\n<p>  <\/p>\n<pre><code class=\"php\">\\App\\Author::whereIn(         'id',         function($query) {             $query-&gt;select('id')                 -&gt;from((new \\App\\Author())-&gt;getTable())                 -&gt;orderBy('id', 'desc')                 -&gt;limit(2);         }     )-&gt;update(['name' =&gt; '\u0416\u043e\u0440\u0436']);<\/code><\/pre>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0445\u043e\u0440\u043e\u0448\u043e, \u0445\u043e\u0442\u044c \u0438 \u043d\u0435 \u043e\u0441\u043e\u0431\u043e \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e. \u0414\u0430 \u0438 query builder \u043e\u043f\u044f\u0442\u044c \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043f\u043e\u0434\u044a\u0435\u0445\u0430\u043b.<\/p>\n<p>  <\/p>\n<h3 id=\"symfony-2\">Symfony<\/h3>\n<p>  <\/p>\n<p>\u0421\u0440\u0430\u0437\u0443 \u0441\u043a\u0430\u0436\u0443, \u0447\u0442\u043e \u0432\u044b\u0440\u0430\u0437\u0438\u0442\u044c \u0447\u0435\u0440\u0435\u0437 DQL \u043c\u043d\u0435 \u044d\u0442\u043e\u0442 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432\u043e\u043e\u0431\u0449\u0435 \u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c, \u0441 \u0432\u043b\u043e\u0436\u0435\u043d\u043d\u044b\u043c\u0438 \u043f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c\u0438 \u0442\u0430\u043c \u0432\u0441\u0451 \u043f\u043b\u043e\u0445\u043e.<\/p>\n<p>  <\/p>\n<p>\u0415\u0441\u0442\u044c, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, query builder, \u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u043b\u043e\u0441\u044c \u0447\u0442\u043e-\u0442\u043e \u0441\u043e\u0432\u0441\u0435\u043c \u0437\u0443\u0431\u043e\u0434\u0440\u043e\u0431\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0435, \u0438 \u044f \u0431\u0440\u043e\u0441\u0438\u043b \u044d\u0442\u0443 \u0437\u0430\u0442\u0435\u044e. ORM \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u043e\u043c\u043e\u0433\u0430\u0442\u044c \u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442\u044c \u0432\u0440\u0435\u043c\u044f, \u0430 \u043d\u0435 \u043d\u0430\u043e\u0431\u043e\u0440\u043e\u0442. \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u043e\u043f\u044b\u0442\u043d\u044b\u0435 \u0441\u0438\u043c\u0444\u043e\u043d\u0438\u0441\u0442\u044b \u0432 \u043a\u043e\u043c\u0435\u043d\u0442\u0430\u0445 \u043f\u043e\u0434\u0441\u043a\u0430\u0436\u0443\u0442 \u043a\u0430\u043a\u043e\u0439-\u043d\u0438\u0431\u0443\u0434\u044c \u043b\u0435\u0433\u043a\u0438\u0439 \u0438 \u0438\u0437\u044f\u0449\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u0441\u0434\u0435\u043b\u0430\u0442\u044c update \u0441 \u043f\u043e\u0434\u0437\u0430\u043f\u0440\u043e\u0441\u043e\u043c.<\/p>\n<p>  <\/p>\n<h2>\u0412\u044b\u0432\u043e\u0434<\/h2>\n<p>  <\/p>\n<p>\u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u043f\u0440\u0438\u0432\u043b\u0435\u043a\u0430\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0438\u0434\u0435\u044e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441\u044b \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0438 \u0438 \u043d\u0435 \u0432\u0434\u0430\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0434\u0435\u0442\u0430\u043b\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445, \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0443\u0434\u0430\u0435\u0442\u0441\u044f \u0434\u0430\u043b\u0435\u043a\u043e \u043d\u0435 \u0432\u0441\u0435\u0433\u0434\u0430. <\/p>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0432\u0441\u0435\u0433\u0434\u0430 \u043e\u0431\u044b\u0447\u043d\u043e \u0438 \u0431\u044b\u0432\u0430\u0435\u0442, \u0438\u0441\u0442\u0438\u043d\u0430 \u0433\u0434\u0435-\u0442\u043e \u043f\u043e\u0441\u0435\u0440\u0435\u0434\u0438\u043d\u0435. \u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u044b\u0445 CRUD-\u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 ORM \u0432\u043f\u043e\u043b\u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0441\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438 \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u0447\u0438\u0442\u0430\u0431\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u0434\u0430. \u041e\u0434\u043d\u0430\u043a\u043e \u0448\u0430\u0433 \u0432\u043f\u0440\u0430\u0432\u043e, \u0448\u0430\u0433 \u0432\u043b\u0435\u0432\u043e \u2014 \u0438 \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u0443\u0434\u043e\u0431\u043d\u0435\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430\u0442\u0438\u0432\u043d\u044b\u043c SQL. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0432\u044b\u0431\u043e\u0440\u043a\u0438\/\u043e\u0431\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f (\u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e, \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043e\u0442\u0447\u0435\u0442\u044b \u0441 \u043e\u043a\u043e\u043d\u043d\u044b\u043c\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f\u043c\u0438 \u0438 \u0440\u0435\u043a\u0443\u0440\u0441\u0438\u0432\u043d\u044b\u043c\u0438 CTE). \u041a\u043e\u043c\u043f\u0440\u043e\u043c\u0438\u0441\u0441\u043d\u044b\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043c\u0430\u043f\u043f\u0438\u043d\u0433 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0445 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043d\u0430 \u043e\u0431\u044a\u0435\u043a\u0442\u044b, \u0414\u043e\u043a\u0442\u0440\u0438\u043d\u0430 \u044d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442.<\/p>\n<p>  <\/p>\n<p>\u0412 \u0441\u043f\u043e\u0440\u0435 ORM vs SQL \u043d\u0435 \u043f\u043e\u0431\u0435\u0434\u0438\u043b \u043d\u0438\u043a\u0442\u043e.<\/p>\n<p>  <\/p>\n<p><em>\u0422\u0435\u043c \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c, \u0432\u0441\u0435\u0445 \u043a\u0442\u043e \u043d\u0430\u043c\u0443\u0447\u0430\u043b\u0441\u044f \u0441 ORM, \u0442\u043e\u0440\u043c\u043e\u0437\u044f\u0449\u0438\u043c\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c\u0438 \u0438 \u043f\u043b\u043e\u0445\u043e\u0439 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c\u044e \u0432 \u0440\u0430\u0431\u043e\u0447\u0438\u0445 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044f\u0445, \u043f\u0440\u0438\u0433\u043b\u0430\u0448\u0430\u0435\u043c \u043d\u0430 <a href=\"https:\/\/pgday.ru\/ru\/2017\/request\/registration?utm_source=habrahabr&amp;utm_medium=blog&amp;utm_campaign=varanio3\"><b>PG Day&#8217;17<\/b><\/a>. \u0423 \u043d\u0430\u0441 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u043e \u0434\u043b\u044f \u0432\u0430\u0441 <a href=\"https:\/\/pgday.ru\/ru\/2017\/papers\/170?utm_source=habrahabr&amp;utm_medium=blog&amp;utm_campaign=varanio3\">\u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e<\/a> <a href=\"https:\/\/pgday.ru\/ru\/2017\/papers\/171?utm_source=habrahabr&amp;utm_medium=blog&amp;utm_campaign=varanio3\">\u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445<\/a> <a href=\"https:\/\/pgday.ru\/ru\/2017\/papers\/189?utm_source=habrahabr&amp;utm_medium=blog&amp;utm_campaign=varanio3\">\u0434\u043e\u043a\u043b\u0430\u0434\u043e\u0432<\/a> \u0438 <a href=\"https:\/\/pgday.ru\/ru\/2017\/request\/registration?talkId=163&amp;utm_source=habrahabr&amp;utm_medium=blog&amp;utm_campaign=varanio3\">\u043c\u0430\u0441\u0442\u0435\u0440-\u043a\u043b\u0430\u0441\u0441\u043e\u0432<\/a> \u0434\u043b\u044f <a href=\"https:\/\/pgday.ru\/ru\/2017\/request\/registration?talkId=135&amp;utm_source=habrahabr&amp;utm_medium=blog&amp;utm_campaign=varanio3\">\u0441\u0430\u043c\u044b\u0445 \u0440\u0430\u0437\u043d\u044b\u0445<\/a> \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445<\/em>!<\/p>\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=\"https:\/\/habrahabr.ru\/post\/328690\/\"> https:\/\/habrahabr.ru\/post\/328690\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p><i>\u0414\u0440\u0443\u0437\u044c\u044f, \u0432\u043d\u043e\u0432\u044c \u043f\u0440\u0438\u0448\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u0430\u0432\u0442\u043e\u0440\u0441\u043a\u043e\u0439 \u043a\u043e\u043b\u043e\u043d\u043a\u0438 \u043a\u043e\u0440\u043f\u043e\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u0431\u043b\u043e\u0433\u0430 <a href=\"https:\/\/pgday.ru\/ru\/2017\/request\/registration?utm_source=habrahabr&amp;utm_medium=blog&amp;utm_campaign=varanio3\"><b>PG Day\u201917<\/b><\/a>. \u041f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u0435\u043c \u0432\u0430\u0448\u0435\u043c\u0443 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044e \u0441\u0440\u0430\u0432\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0430\u043d\u0430\u043b\u0438\u0437 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 PostgreSQL \u0438\u0437 \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 ORM \u043e\u0442 <a href=\"https:\/\/habrahabr.ru\/users\/varanio\/\" class=\"user_link\">varanio<\/a>.<\/i><\/p>\n<p>  <img decoding=\"async\" align=\"left\" src=\"https:\/\/habrastorage.org\/web\/173\/81a\/dc8\/17381adc847c42b5bfcdba54ac2c2b80.png\"\/>  <\/p>\n<p>ORM (Object-Relational Mapping), \u043f\u043e \u0438\u0434\u0435\u0435, \u0434\u043e\u043b\u0436\u0435\u043d \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c \u043d\u0430\u0441 \u043e\u0442 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f SQL \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0438, \u0432 \u0438\u0434\u0435\u0430\u043b\u0435, \u0432\u043e\u043e\u0431\u0449\u0435 \u0430\u0431\u0441\u0442\u0440\u0430\u0433\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0442 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445 (\u043e\u0442 \u0441\u043f\u043e\u0441\u043e\u0431\u0430 \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445), \u0447\u0442\u043e\u0431\u044b \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u043a\u043b\u0430\u0441\u0441\u0430\u043c\u0438, \u0432 \u0442\u043e\u0439 \u0438\u043b\u0438 \u0438\u043d\u043e\u0439 \u0441\u0442\u0435\u043f\u0435\u043d\u0438 \u0432\u044b\u0440\u0430\u0436\u0430\u044e\u0449\u0438\u043c\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u0431\u0438\u0437\u043d\u0435\u0441-\u043b\u043e\u0433\u0438\u043a\u0438, \u043d\u0435 \u0437\u0430\u0434\u0430\u0432\u0430\u044f\u0441\u044c \u0432\u043e\u043f\u0440\u043e\u0441\u043e\u043c, \u0432 \u043a\u0430\u043a\u0438\u0445 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445 \u0432\u0441\u0451 \u044d\u0442\u043e \u043f\u043e \u0444\u0430\u043a\u0442\u0443 \u043b\u0435\u0436\u0438\u0442.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043d\u0430\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u044d\u0442\u043e \u0443\u0434\u0430\u0435\u0442\u0441\u044f \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u043c \u043d\u0430 PHP. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0442\u0438\u043f\u0438\u0447\u043d\u044b\u0445 \u043a\u0435\u0439\u0441\u043e\u0432 \u0438 \u0441\u0440\u0430\u0432\u043d\u0438\u043c ORM \u0441 \u0433\u043e\u043b\u044b\u043c SQL, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u043c \u0432\u0440\u0443\u0447\u043d\u0443\u044e.<\/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-286360","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/286360","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=286360"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/286360\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=286360"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=286360"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=286360"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}