{"id":2940,"date":"2021-07-21T08:55:04","date_gmt":"2021-07-21T08:55:04","guid":{"rendered":"https:\/\/www.bearloga.space\/?page_id=2940"},"modified":"2021-07-21T08:55:04","modified_gmt":"2021-07-21T08:55:04","slug":"otnosheniya-mnogie-ko-mnogim","status":"publish","type":"page","link":"https:\/\/www.bearloga.space\/uk\/otnosheniya-mnogie-ko-mnogim\/","title":{"rendered":"\u041e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043c\u043d\u043e\u0433\u0438\u0435 \u043a\u043e \u043c\u043d\u043e\u0433\u0438\u043c"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>\u0421\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u00ab\u043c\u043d\u043e\u0433\u0438\u0435 \u043a\u043e \u043c\u043d\u043e\u0433\u0438\u043c\u00bb<\/strong>&nbsp;\u043c\u0435\u0436\u0434\u0443 \u0434\u0432\u0443\u043c\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c\u0438 \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u0435\u0442\u0441\u044f \u043f\u0443\u0442\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438 \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u0443 \u043d\u0435\u0435 \u0431\u044b\u043b\u043e \u0434\u0432\u0430 \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u043a\u043b\u044e\u0447\u0430 \u2014 \u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u043e\u0442 \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430 \u043a\u0430\u0436\u0434\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u044b.&nbsp;\u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043a\u043b\u0430\u0441\u0441\u044b, \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u043c\u044b\u0435 \u043d\u0430 \u0434\u0432\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0438\u043c\u0435\u044e\u0442 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u0441 \u043d\u0430\u0431\u043e\u0440\u043e\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 \u0434\u0440\u0443\u0433\u0438\u0445 \u0442\u0430\u0431\u043b\u0438\u0446 \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0439, \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u044b\u0439 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0432\u0442\u043e\u0440\u0438\u0447\u043d\u043e\u0433\u043e \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 Relations ().<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 SQLite (mycollege.db) \u0441 \u0434\u0432\u0443\u043c\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c\u0438 \u2014 \u043e\u0442\u0434\u0435\u043b \u0438 \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a.&nbsp;\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u043c, \u0447\u0442\u043e \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u044c\u044e \u0431\u043e\u043b\u0435\u0435 \u0447\u0435\u043c \u043e\u0434\u043d\u043e\u0433\u043e \u043e\u0442\u0434\u0435\u043b\u0430, \u0430 \u0432 \u043e\u0442\u0434\u0435\u043b\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0431\u043e\u043b\u0435\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u0430.&nbsp;\u042d\u0442\u043e \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u043c\u043d\u043e\u0433\u0438\u0445 \u043a\u043e \u043c\u043d\u043e\u0433\u0438\u043c.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u043e\u0432 \u0438 \u043e\u0442\u0434\u0435\u043b\u043e\u0432, \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u0441 \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439 \u043e\u0442\u0434\u0435\u043b\u043e\u0432 \u0438 \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u043e\u0432, \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">from sqlalchemy import create_engine, ForeignKey, Column, Integer, String\nengine = create_engine('sqlite:\/\/\/mycollege.db', echo = True)\nfrom sqlalchemy.ext.declarative import declarative_base\nBase = declarative_base()\nfrom sqlalchemy.orm import relationship\n\nclass Department(Base):\n   __tablename__ = 'department'\n   id = Column(Integer, primary_key = True)\n   name = Column(String)\n   employees = relationship('Employee', secondary = 'link')\n   \nclass Employee(Base):\n   __tablename__ = 'employee'\n   id = Column(Integer, primary_key = True)\n   name = Column(String)\n   departments = relationship(Department,secondary='link')<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043a\u043b\u0430\u0441\u0441 Link.&nbsp;\u041e\u043d \u0441\u0432\u044f\u0437\u0430\u043d \u0441 \u0442\u0430\u0431\u043b\u0438\u0446\u0435\u0439 \u0441\u0441\u044b\u043b\u043e\u043a \u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u044b Department_id \u0438 employee_id, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0441\u0441\u044b\u043b\u0430\u044e\u0449\u0438\u0435\u0441\u044f \u043d\u0430 \u043f\u0435\u0440\u0432\u0438\u0447\u043d\u044b\u0435 \u043a\u043b\u044e\u0447\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043e\u0442\u0434\u0435\u043b\u043e\u0432 \u0438 \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u043e\u0432.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">class Link(Base):\n   __tablename__ = 'link'\n   department_id = Column(\n      Integer, \n      ForeignKey('department.id'), \n      primary_key = True)\n\nemployee_id = Column(\n   Integer, \n   ForeignKey('employee.id'), \n   primary_key = True)<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u043e\u0442\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u0443 \u043a\u043b\u0430\u0441\u0441\u0430 Department \u0435\u0441\u0442\u044c \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u043e\u0432, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0439 \u0441 \u043a\u043b\u0430\u0441\u0441\u043e\u043c Employee.&nbsp;\u0412\u0442\u043e\u0440\u0438\u0447\u043d\u043e\u043c\u0443 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043d\u0430\u0437\u043d\u0430\u0447\u0430\u0435\u0442\u0441\u044f \u0441\u0441\u044b\u043b\u043a\u0430 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u0410\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e, \u043a\u043b\u0430\u0441\u0441 Employee \u0438\u043c\u0435\u0435\u0442 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u043e\u0442\u0434\u0435\u043b\u043e\u0432, \u0441\u0432\u044f\u0437\u0430\u043d\u043d\u044b\u0439 \u0441 \u043a\u043b\u0430\u0441\u0441\u043e\u043c Department.&nbsp;\u0412\u0442\u043e\u0440\u0438\u0447\u043d\u043e\u043c\u0443 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043d\u0430\u0437\u043d\u0430\u0447\u0430\u0435\u0442\u0441\u044f \u0441\u0441\u044b\u043b\u043a\u0430 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u0412\u0441\u0435 \u044d\u0442\u0438 \u0442\u0440\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441\u043e\u0437\u0434\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u0430:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Base.metadata.create_all(engine)<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u041a\u043e\u043d\u0441\u043e\u043b\u044c Python \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b CREATE TABLE \u2014<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">CREATE TABLE department (\n   id INTEGER NOT NULL,\n   name VARCHAR,\n   PRIMARY KEY (id)\n)\n\nCREATE TABLE employee (\n   id INTEGER NOT NULL,\n   name VARCHAR,\n   PRIMARY KEY (id)\n)\n\nCREATE TABLE link (\n   department_id INTEGER NOT NULL,\n   employee_id INTEGER NOT NULL,\n   PRIMARY KEY (department_id, employee_id),\n   FOREIGN KEY(department_id) REFERENCES department (id),\n   FOREIGN KEY(employee_id) REFERENCES employee (id)\n)<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u044d\u0442\u043e, \u043e\u0442\u043a\u0440\u044b\u0432 mycollege.db \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e SQLiteStudio, \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u043d\u0430 \u0441\u043a\u0440\u0438\u043d\u0448\u043e\u0442\u0430\u0445 \u043d\u0438\u0436\u0435<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/coderlessons.com\/wp-content\/uploads\/2019\/07\/department_table.jpg\" alt=\"\u0421\u0442\u043e\u043b \u043e\u0442\u0434\u0435\u043b\u0430\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/coderlessons.com\/wp-content\/uploads\/2019\/07\/employee_table.jpg\" alt=\"\u0421\u0442\u043e\u043b \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u0430\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/coderlessons.com\/wp-content\/uploads\/2019\/07\/link_table.jpg\" alt=\"\u0422\u0430\u0431\u043b\u0438\u0446\u0430 \u0441\u0441\u044b\u043b\u043e\u043a\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u0417\u0430\u0442\u0435\u043c \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0442\u0440\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 Department \u0438 \u0442\u0440\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 Employee, \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u043d\u0438\u0436\u0435:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">d1 = Department(name = \"Accounts\")\nd2 = Department(name = \"Sales\")\nd3 = Department(name = \"Marketing\")\n\ne1 = Employee(name = \"John\")\ne2 = Employee(name = \"Tony\")\ne3 = Employee(name = \"Graham\")<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u041a\u0430\u0436\u0434\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0438\u043c\u0435\u0435\u0442 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438, \u0438\u043c\u0435\u044e\u0449\u0438\u0439 \u043c\u0435\u0442\u043e\u0434 append ().&nbsp;\u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u044b Employee \u0432 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044e Employees \u043e\u0431\u044a\u0435\u043a\u0442\u0430 Department.&nbsp;\u0422\u043e\u0447\u043d\u043e \u0442\u0430\u043a \u0436\u0435 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442\u044b Department \u0432 \u0430\u0442\u0440\u0438\u0431\u0443\u0442 \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u0438 \u0434\u0435\u043f\u0430\u0440\u0442\u0430\u043c\u0435\u043d\u0442\u043e\u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432 Employee.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">e1.departments.append(d1)\ne2.departments.append(d3)\nd1.employees.append(e3)\nd2.employees.append(e2)\nd3.employees.append(e1)\ne3.departments.append(d2)<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u0412\u0441\u0435, \u0447\u0442\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0441\u0435\u0439\u0447\u0430\u0441, \u044d\u0442\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u0435\u0430\u043d\u0441\u0430, \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0432\u0441\u0435 \u043e\u0431\u044a\u0435\u043a\u0442\u044b \u043a \u043d\u0435\u043c\u0443 \u0438 \u0437\u0430\u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f, \u043a\u0430\u043a \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u043d\u0438\u0436\u0435 \u2014<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">from sqlalchemy.orm import sessionmaker\nSession = sessionmaker(bind = engine)\nsession = Session()\nsession.add(e1)\nsession.add(e2)\nsession.add(d1)\nsession.add(d2)\nsession.add(d3)\nsession.add(e3)\nsession.commit()<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440\u044b SQL \u0431\u0443\u0434\u0443\u0442 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 Python \u2014<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">INSERT INTO department (name) VALUES (?) ('Accounts',)\nINSERT INTO department (name) VALUES (?) ('Sales',)\nINSERT INTO department (name) VALUES (?) ('Marketing',)\nINSERT INTO employee (name) VALUES (?) ('John',)\nINSERT INTO employee (name) VALUES (?) ('Graham',)\nINSERT INTO employee (name) VALUES (?) ('Tony',)\nINSERT INTO link (department_id, employee_id) VALUES (?, ?) ((1, 2), (3, 1), (2, 3))\nINSERT INTO link (department_id, employee_id) VALUES (?, ?) ((1, 1), (2, 2), (3, 3))<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u0427\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c \u0432\u043b\u0438\u044f\u043d\u0438\u0435 \u0432\u044b\u0448\u0435\u0443\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435 SQLiteStudio \u0438 \u043f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0439\u0442\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445 \u043e\u0442\u0434\u0435\u043b\u043e\u0432, \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u043e\u0432 \u0438 \u0441\u0441\u044b\u043b\u043e\u043a \u2014<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/coderlessons.com\/wp-content\/uploads\/2019\/07\/department_table_data.jpg\" alt=\"\u0414\u0430\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043e\u0442\u0434\u0435\u043b\u043e\u0432\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/coderlessons.com\/wp-content\/uploads\/2019\/07\/employee_table_data.jpg\" alt=\"\u0414\u0430\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441\u043e\u0442\u0440\u0443\u0434\u043d\u0438\u043a\u043e\u0432\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/coderlessons.com\/wp-content\/uploads\/2019\/07\/link_table_data.jpg\" alt=\"\u0414\u0430\u043d\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441\u0432\u044f\u0437\u0435\u0439\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u0427\u0442\u043e\u0431\u044b \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435, \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u0435 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u2014<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">from sqlalchemy.orm import sessionmaker\nSession = sessionmaker(bind = engine)\nsession = Session()\n\nfor x in session.query( Department, Employee).filter(Link.department_id == Department.id, \n   Link.employee_id == Employee.id).order_by(Link.department_id).all():\n   print (\"Department: {} Name: {}\".format(x.Department.name, x.Employee.name))<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u0421\u043e\u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u00ab\u043c\u043d\u043e\u0433\u0438\u0435 \u043a\u043e \u043c\u043d\u043e\u0433\u0438\u043c\u00bb&nbsp;\u043c\u0435\u0436\u0434\u0443 \u0434\u0432\u0443\u043c\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u043c\u0438 \u0434\u043e\u0441\u0442\u0438\u0433\u0430\u0435\u0442\u0441\u044f \u043f\u0443\u0442\u0435\u043c \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0430\u0441\u0441\u043e\u0446\u0438\u0430\u0446\u0438\u0438 \u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u0443 \u043d\u0435\u0435 \u0431\u044b\u043b\u043e \u0434\u0432\u0430 \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u043a\u043b\u044e\u0447\u0430 \u2014 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[103],"tags":[],"class_list":["post-2940","page","type-page","status-publish","hentry","category-sqlalchemy"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.bearloga.space\/uk\/wp-json\/wp\/v2\/pages\/2940","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bearloga.space\/uk\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.bearloga.space\/uk\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.bearloga.space\/uk\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bearloga.space\/uk\/wp-json\/wp\/v2\/comments?post=2940"}],"version-history":[{"count":0,"href":"https:\/\/www.bearloga.space\/uk\/wp-json\/wp\/v2\/pages\/2940\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.bearloga.space\/uk\/wp-json\/wp\/v2\/media?parent=2940"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bearloga.space\/uk\/wp-json\/wp\/v2\/categories?post=2940"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bearloga.space\/uk\/wp-json\/wp\/v2\/tags?post=2940"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}