English 中文(简体)
How to delete all user roles in Kohana 3
原标题:

I m using ORM Auth module and it s difficult to figure out how to do it. I ve tried this case:

$user = ORM::factory( user , $id);
$user->roles->delete_all();

And got error ErrorException [ Fatal Error ]: Call to undefined method Database_Query_Builder_Delete::join()

However $user->roles->find_all(); gives me exactly what i want.

最佳回答

Instead of deleting roles from the database, what you want to do is remove the relationships between the user model and the roles model. You can use the ORM remove() method.

foreach ($user->roles->find_all() as $role)
{
    $user->remove( roles , $role);
}
问题回答

According to version 3.1.3.1 code for Kohana_ORM class, the ORM method "remove($alias, $far_keys=NULL)" if you do not pass the second parameter, it will destroy all related entries.

$user->remove( roles );

Just create a ticket for this feature. You can use a code suggested.





相关问题
Kohana - subfolders within views folder

I m working on the admin section of a site using Kohana. I ve created a "admin" subfolder within the views folder to store admin views. I m also using a modified instance of the Template Controller ...

approach for "site down for maintenance"

I have been using Joomla and I love its administrative facility to put the site down for maintenance. As I have seen, all requests to the site if it is in maintenance mode is routed to a single page. ...

Kohana 3: using maintainable routes

I m using Kohana v3 for a web project, and today I found myself writing this: echo Html::anchor( user/view/ .$user->id, "See user s profile"); If I rename the action_view method in the User ...

Is using a Mail Model in MVC incorrect?

I have built a model in some of my MVC websites to assist with sending emails, generally I do something like this $mail = new Mail_Model; $mail->to( me@somewhere.com ); $mail->from( you@...

help on building a basic php search engine

i looked for tutorials everywhere but just can t seem to get a good one... a search page with pagination, column header sorting, and multiple filtering(filters are in checkboxes) the problem: had ...

What s the proper MVC way to do this....?

Quick question about general MVC design principle in PHP, using CodeIgniter or Kohana (I m actually using Kohana). I m new to MVC and don t want to get this wrong... so I m wondering if i have ...

Kohana Error... Attempt to assign property of non-object

So I m trying to go through the Version 3 Guide of Kohana and keep getting an error on the hello world create view part. ErrorException [ Warning ]: Attempt to assign property of non-object Line 8: $...

热门标签