Are Doctrine2 repositories a good place to save my entities?

后端 未结 3 414
我在风中等你
我在风中等你 2021-01-29 20:20

When I read docs about repositories, it is often to work with entities & collection but in a \"read-only\" manner.

There are never examples where repositories have m

3条回答
  •  暖寄归人
    2021-01-29 20:45

    Well, how do you get your repository when not using the entityManager? After all, the entities are not going to be saved magically without a connection to the database, so your service must somehow be aware of any kind of connection.

    I don't know about the SOA Services, but in my eyes it makes no difference at all if you use $_em->getRepository()->save($entity) or $_em->persist($entity). On the other hand, if you use flush in your repository, you might end up with way more queries than needed as your repository is now aware of the business logic.

    I think there is a way to do this "the SOA way", but I guess it's not persisting the entities within the repository.

提交回复
热议问题