Reputation: 2486
Lets assume i have the following entities:
class User{
private $id;
private $name;
private $active;
private $clients;
}
class Client{
private $id;
private $name;
private $active;
private $subdomain;
private $users;
}
class Subdomain{
private $id;
private $name;
private $active;
}
With all their setters and getters, orm tables and relations. Users and Clients have many-to-many relation while client and subdomain one-to-one relation.
What i want to achieve is not to activate the client till at least one user is active and that client wont be active till its subdomain is active.
Now i now that this can be done simply by creating some function and call it whenever an entity is updated and when i have all isActive()
is true then i would call setActive on the desired user. But i was searching around for something like an Entity or record watcher so whenever a record is updated automatically check some fields and then update a field on that user. In other words i dont want to manually call the setActive() and checkForClientAndSubdomainActivity() functions. So is there anything like that ready built out there? or should i build it?
Thanks in advance, i cut most of the code just for the ease of read.
Upvotes: 0
Views: 157
Reputation: 290
You can use Doctrine's events to do your operations everytime you perform an update on a specific entity (there is more events) : doc.
Upvotes: 3