Welcome Guest, Not a member yet? Register   Sign In
Problem with using DataMapper ORM
#1

[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 {
   var $has_many = array('user');
}

class User extends DataMapper {
   var $has_one = array('role');
}

Thank you...
#2

[eluser]johnpeace[/eluser]
This might have some info helpful for you...

http://stackoverflow.com/questions/13464...apper-find.
#3

[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.
#4

[eluser]WanWizard[/eluser]
You can run a related count, and only delete if the result is 0?

Code:
if ($role->user->count() == 0)
{
    $role->delete();
}
#5

[eluser]burakdirin[/eluser]
Thank you for helping.




Theme © iAndrew 2016 - Forum software by © MyBB