Sorry guys for the missleading terminology here, I wrote Entity but
really meant Model.

After a while of digging I ended up with a bunch of servie classes
(like ericclemmons said), a few custom validation constraints and a
custom repository.
Thanks guys for helping me out!

On Apr 5, 5:48 pm, ericclemmons <e...@smarterspam.com> wrote:
> Ok, if it's "Entity", sure, then it's bad practice.  In his example,
> it is clearly a "PageModel", so he can inject whatever dependencies he
> needs for his domain model to work as expected:
>
> <?php
> class PageModel
> {
>
>    public function __construct($layoutManager)
>    { ...
>
> Obviously, the problem here is if he's trying to inject services into
> an *entity* that's coming back from Doctrine's EntityPersister.
>
> If you're not working with entities and you're actually working with
> domain models, do yourself a favor & create a "PageService" for
> fetching/saving your domain models and leave Doctrine for the
> persistence of data.
>
> On Apr 4, 9:19 pm, Carl <carl.par...@gmail.com> wrote:
>
>
>
>
>
>
>
> > Conceptually it's bad practice because entities are just meant to 
> > *store*data. The only methods they should have are simple set and get 
> > methods.
> > Nothing more. If you start adding other logic to them, then you're changing
> > the purpose of entities and it can start to make your code more difficult to
> > maintain and modify.
>
> > It's considered better practice to put the kind of code you have in your
> > snippet in Doctrine 2 repository classes or directly in one of your services
> > (or a combination of the two), depending on what it is you're trying to do.
> > You can specific Doctrine repository classes in your ORM pretty easily.
>
> > If you're using YAML and your entity class is called Wicked, you can specify
> > a repository as follows:
>
> > repositoryClass: SomeVendor\MyAwesomeBundle\Model\WickedRepository
>
> > ...where SomeVendor\MyAwesomeBundle\Model\WickedRepository is the location
> > of your repository class.

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en

Reply via email to