Access to entity repository from an entity

New topics about Symfony 2 should go here

Moderators: dcobalt, tiagojsag

Access to entity repository from an entity

Postby eoruxorit » Tue Apr 10, 2012 7:07 pm

Hello,

Suppose that I have the class Task, and this class has a TaskState.
TaskState has an id, name and description.

Both classes are Doctrine entities and are mapped to the Task and TaskState tables respectively.

My problem is the following, Task has a method called lock, this method needs to change the state of the Task entity, assigning a existent TaskState object that represent the "locked" state.

To have semantic meaning, this need to have no parameters, but, I need to access to the TaskState repository the get the suitable object to accomplish this logic.
So, how can I solve this problem? Have I design issues?

Thanks in advance!
eoruxorit
Junior Member
 
Posts: 7
Joined: Fri Mar 30, 2012 5:09 pm

Re: Access to entity repository from an entity

Postby dreipunktnull » Wed Apr 11, 2012 9:19 am

Hi,

I think you should put this logic in a service that provides some lockTask(Task $task) method because entities should not have dependencies. You would only need to inject the doctrine.orm.entity_manager service to get the needed repo.
User avatar
dreipunktnull
Faithful Member
 
Posts: 1244
Joined: Fri Jun 17, 2011 10:03 am
Location: Germany


Return to General Symfony 2 discussion

Who is online

Users browsing this forum: W3C [Validator] and 6 guests