Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Database_Query_Builder_Delete error
  • Hi again! When I delete a many to many relationship I get this bug coming up: ErrorException [ Error ]: Call to undefined method Fuel\Core\Database_Query_Builder_Delete::delete()
    PKGPATH/orm/classes/manymany.php @ line 292

    287            next($this->key_from);
    288        }
    289        \Debug::dump($query);
    290        \Debug::backtrace();
    291        //die();
    292        $query->delete();
    293
    294        $cascade = is_null($cascade) ? $this->cascade_delete : (bool) $cascade;
    295        if ($cascade and ! empty($model_to))
    296        {
    297            foreach ($models_to as $m)
    

    The model code is:
    class Model_Users extends Orm\Model { 
    
     protected static $_many_many = array(
         'sites' => array(
             'key_from' => 'id',
             'key_through_from' => 'user_id', // column 1 from the table in between, should match a posts.id
             'table_through' => 'sites_users', // both models plural without prefix in alphabetical order
             'key_through_to' => 'site_id', // column 2 from the table in between, should match a users.id
             'model_to' => 'Model_Sites',
             'key_to' => 'id',
             'cascade_save' => true,
             'cascade_delete' => false,
         )
     );
     
    }
    

    And the code for deletion is the code from the scafolding:
    public function action_delete($id = null)
     {
      if ($users = Model_Users::find($id))
      {
       $users->delete();
       
       Session::set_flash('notice', 'Deleted user #' . $id);
      }
    
      else
      {
       Session::set_flash('notice', 'Could not delete user #' . $id);
      }
    
      Response::redirect('users');
     }
    

    Finally, here is a debug dump of the Database_Query_Builder_Delete object:
    object(Fuel\Core\Database_Query_Builder_Delete)#13 (9) {
      ["_table":protected]=>
      string(11) "sites_users"
      ["_where":protected]=>
      array(1) {
        [0]=>
        array(1) {
          ["AND"]=>
          array(3) {
            [0]=>
            string(7) "user_id"
            [1]=>
            string(1) "="
            [2]=>
            string(1) "6"
          }
        }
      }
      ["_order_by":protected]=>
      array(0) {
      }
      ["_limit":protected]=>
      NULL
      ["_type":protected]=>
      int(4)
      ["_lifetime":protected]=>
      NULL
      ["_sql":protected]=>
      string(0) ""
      ["_parameters":protected]=>
      array(0) {
      }
      ["_as_object":protected]=>
      bool(false)
    }
    

    Anyone have any ideas? I've spent an hour or so trying to figure it out, so sorry if it's something straight forward I've missed. It's been a long day! Cheers,
    Steve
  • This has been fixed in the dev branch and will be in the next release.
  • Again, thanks for the speedy response! Thats good news it's been fixed! Thought I was going crazy! Any time frame on the next release? Or is the dev branch stable enough to use?
  • Next release (RC3) should be soon, it's almost ready to be called final (lack of a hell of a lot of core unit tests is preventing that from happening soon). There's not much holding up the next release, no experimental stuff in the dev branch currently but a hell of a lot of bugfixes - so it's probably more stable right now.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion