2

I need to map an entity to a Postgres view which doesn't have primary id, no id defined.

Views in Postgresql can't have primary keys. On the same time Doctrine entities need a primary key defined.

Can I create a "virtual" property some like this?

class MyEntityClass
{
    /**
     * @var int
     *
     * @ORM\Id
     * @ORM\Column(type="uuid")
     */
     private $id;

     public function getId(): string
     {
          return generate_unique_id_just_for_my_join()
     }
 }

This entity need to be used only for select data. Never for insert/update.

2
  • Overriding getId is not going to help. Doctrine itself transfers data directly between entity properties and table columns. Check the Doctrine docs to see how to use compound keys for the id. Commented Dec 21, 2020 at 17:04
  • Ok i'll check thanks. This entity need to be used only for select data. Never for insert/update Commented Dec 21, 2020 at 18:35

1 Answer 1

0

Problem solved using Doctrine somposite primary keys

https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/tutorials/composite-primary-keys.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.