{"id":19697173,"url":"https://github.com/janit/doctrine-inheritance-example","last_synced_at":"2025-04-29T11:32:25.327Z","repository":{"id":69358389,"uuid":"106166606","full_name":"janit/doctrine-inheritance-example","owner":"janit","description":"A simple Symfony Flex app example of using Doctrine ORM with inheritance of Entity classes","archived":false,"fork":false,"pushed_at":"2017-10-11T07:13:16.000Z","size":34,"stargazers_count":43,"open_issues_count":0,"forks_count":8,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-26T04:25:32.130Z","etag":null,"topics":["doctrine-orm","doctrine2","php","symfony"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/janit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-10-08T10:08:45.000Z","updated_at":"2025-03-11T18:22:07.000Z","dependencies_parsed_at":"2023-02-22T20:45:19.857Z","dependency_job_id":null,"html_url":"https://github.com/janit/doctrine-inheritance-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janit%2Fdoctrine-inheritance-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janit%2Fdoctrine-inheritance-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janit%2Fdoctrine-inheritance-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/janit%2Fdoctrine-inheritance-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/janit","download_url":"https://codeload.github.com/janit/doctrine-inheritance-example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251494114,"owners_count":21598236,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["doctrine-orm","doctrine2","php","symfony"],"created_at":"2024-11-11T19:37:24.203Z","updated_at":"2025-04-29T11:32:25.322Z","avatar_url":"https://github.com/janit.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Doctrine ORM entity inheritance example (with Symfony Flex)\n\nThis is an example of using Doctrine ORM entity inheritance with the Symfony Flex framework.\nIt is mostly a reminder to myself, but others may find it useful as a reference.\n\nMore indepth information about Doctrine ORM inheritance:\n\n - \u003ca href=\"http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/inheritance-mapping.html\"\u003eInheritance Mapping in Doctrine documentation\u003c/a\u003e\n - \u003ca href=\"https://blog.liip.ch/archive/2012/03/27/table-inheritance-with-doctrine.html\"\u003eTable Inheritance with Doctrine\u003c/a\u003e\n\n## Structure and table overview\n\nThis package contains six Doctrine ORM entity classes in [src/Entity](https://github.com/janit/doctrine-inheritance-example/tree/master/src/Entity) that are configured via \nannotations. The included entities use inheritance with two methods (`SINGLE_TABLE` and `JOINED`).\n\nThere are two separate data structures:\n\n - Animal\n   - id\n   - color\n     - Cat\n       - name\n     - Dog\n        - kennel\n\n\n - Vehicle\n   - id\n   - color\n     - Moped\n       - tuning\n     - Truck\n       - wheelage\n\nThe relationships are configured using annotations in the parent class, for example:\n\n```\n * @ORM\\InheritanceType(\"SINGLE_TABLE\")\n * @ORM\\DiscriminatorColumn(name=\"discr\", type=\"string\")\n * @ORM\\DiscriminatorMap({\"animal\" = \"Animal\", \"cat\" = \"Cat\", \"dog\" = \"Dog\"})\n```\n\n### Single table inheritance\n\nThe `Animal` base entity class is inherited using `SINGLE_TABLE` strategy by the `Cat` and `Dog`\nsub entities. The generated schema when using this strategy contains a single table with all\nthe columns for each sub entity.\n\n#### animal table \n\n| id | discr | color | name  | kennel         |\n|----|-------|-------|-------|----------------|\n| 1  | cat   | black | Jallu |                |\n| 2  | cat   | grey  | Ossi  |                |\n| 3  | dog   | brown |       | The Dogg Pound |\n  \n\n### Joined inheritance\n\nThe `Vehicle` base entity class is inherited using `JOINED` strategy by `Truck` and `Moped`\nclasses. With this strategy generated schema contains individual tables for each sub entity.\n\n#### vehicle table\n\n| id | color | discr |\n|----|-------|-------|\n| 1  | Blue  | truck |\n| 2  | Red   | truck |\n| 3  | Black | moped |\n\n#### truck table\n\n| id | wheelage |\n|----|----------|\n| 1  | 10       |\n| 2  | 18       |\n\n#### moped table\n\n| id | tuning  |\n|----|---------|\n| 3  | Regular |\n\n## Installation\n\nPrerequisites for installation are PHP 7.1, Composer and a supported database (Postgres, MariaDB, MySQL, SQLite...).\n\nThe first step is to copy the `.env.dist` to `.env` and configure a working database connection.\n\nOnce this is done, proceed with installing packages and setting up the database:\n\n```\n$ composer install\n$ ./bin/console doctrine:database:create\n$ ./bin/console doctrine:schema:update --force\n```\n\nOnce the the installation is complete, proceed with running the local devserver:\n\n```\n$ make serve\n```\n\nYou can find the entity administration interface (using EasyAdminBundle) in http://localhost:8000/admin\n\nCreate some entities and observe the database schema and entities.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjanit%2Fdoctrine-inheritance-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjanit%2Fdoctrine-inheritance-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjanit%2Fdoctrine-inheritance-example/lists"}