fuel / orm

Fuel PHP Framework - Fuel v1.x ORM
http://fuelphp.com/docs/packages/orm/intro.html
151 stars 95 forks source link

Many to Many Relationships #440

Closed nickhagen closed 3 years ago

nickhagen commented 3 years ago

Trying to use many-many relationships on the latest version of the ORM causes database exceptions with Many-Many relationships!

The following code works on dev-1.9/develop#9b7e24253948fd9884c4c2120d999786691ee64b ... but the latest version receives the below error:

$adminRole = Model_Role::forge([
     'name' => 'admin',
     'description' => 'test',
]);
$adminRole->save();

$user = Model_User::forge([
      'email_address' => 'test@testing.com',
      'password' => '123534123',
]);
$user->save();

$user->roles[$adminRole->id] = $adminRole;
$user->save();
Fuel\Core\Database_Exception [ 42000 (1064) ]:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE `id` = '17'' at line 1 with query: "UPDATE `users` SET WHERE `id` = '17'"
nickhagen commented 3 years ago

Here is the relationship defined on Model_User

protected static $_many_many = [
        'roles' => [
            'key_from' => 'id',
            'key_through_from' => 'user_id',
            'table_through' => 'users_roles',
            'key_through_to' => 'role_id',
            'key_to' => 'id',
            'model_to' => 'Model_Role',
            'cascade_save' => true,
            'cascade_delete' => false,
        ],
    ];
WanWizard commented 3 years ago

It's missing the entire SET statement, weird. Nothing has changed to SQL generation.

Currently debugging another issue, I'll have a look at this as well.