Problem with using DataMapper ORM |
[eluser]burakdirin[/eluser]
Hello, I have a problem using a Datamapper with CI. I created 2 tables. Table 1 name : Roles Table 2 name : Users There is the relationship between the tables and connected with foreign key in mysql Roles --------- id name -------------------- User --------- id name role_id I don't want the deletion if role is being used. But, it deleted quickly with '$role->delete()' command. Code: class Role extends DataMapper { Thank you...
[eluser]johnpeace[/eluser]
This might have some info helpful for you... http://stackoverflow.com/questions/13464...apper-find.
[eluser]burakdirin[/eluser]
Thanks for comment but, I just want if role name is not used in user table then it can be deleted. Can I do it automatically in Model ? Because I do not want to check always.
[eluser]WanWizard[/eluser]
You can run a related count, and only delete if the result is 0? Code: if ($role->user->count() == 0)
|
Welcome Guest, Not a member yet? Register Sign In |