Ticket #714 (closed Bug: fixed)

Opened 4 months ago

Last modified 4 months ago

ORM::add method insufficient

Reported by: wouter Owned by: Shadowhand
Priority: major Milestone: 2.2
Component: Libraries:ORM Version: SVN HEAD
Keywords: ORM add Cc:

Description

I was trying to get the Auth module to work with (today's) SVN version of Kohana and I ran into a few issues.

Something small first, the pivot table should be named 'roles_users' (instead of 'users_roles' as documented in view/install.php).

Secondly, on creating a new user, the Auth_Demo controller runs: <pre><code>if ($user->save() AND $user->add('role', 'login'))</code></pre>

However, the ORM::add method will now try to add a row to the roles_users table with role_id = 'login', while it should be role_id = 1. To me it seems this is because the ORM::add method does load the roles model, but it does not load the actual role based on the roles' name.

I got it running by changing (in the ORM::add method): <pre><code>// Load the model $model = ORM::factory($object);</code></pre>

into: <pre><code>// Load the model $model = ORM::factory($object,$id);</code></pre>

and <pre><code>$model->foreign_key(NULL, $join_table) => $id,</code></pre>

into

<pre><code>$model->foreign_key(NULL, $join_table) => $model->primary_key_value,</code></pre>

I'm not sure if this is entirely correct, maybe you need to check if the supplied ID actually exists?! I'm still in the process of understanding ORM, and the Kohana ORM libraries.

Change History

Changed 4 months ago by Shadowhand

  • status changed from new to assigned

Changed 4 months ago by Nowaker

You should change line:

if ($user->save() AND $user->add('role', 'login'))

Just into:

$user->save();
$user->add('role', 'login');

However, it should be repaired.

Changed 4 months ago by Shadowhand

  • status changed from assigned to closed
  • resolution set to fixed

Fixed in r3253.

Note: See TracTickets for help on using tickets.