Guilherme Sehn Fri Jan 14 22:02:31 -0500 2011

Subject: Undefined method

Hello,

I am having some trouble when I try to run a delete query with PHP ActiveRecord. I'm running PHP 5.3.1 and MySQL 5.1.44 in XAMPP for Mac OS X.

When I try to use Comment::delete(id), I get:

Fatal error: Call to undefined method AdminController::verify_not_readonly() in /Applications/XAMPP/xamppfiles/htdocs/lib/activerecord/lib/Model.php on line 973

Here is the part of of AdminController.php code, where the error is ocurring:

class AdminController {
function __construct() {
//...
}

function deleteComment($param)
{
Comment::delete($param->id);
exit;
}
}

And here is the Comment.php model:

class Comment extends ActiveRecord\Model {
static $belongs_to = array(
array('posts')
);
}


Jono B Sun Jan 16 11:45:33 -0500 2011

You have to load the model first, before trying to delete it.

See http://www.phpactiverecord.org/projects/main/wiki/Basic_CRUD

Guilherme Sehn Sun Jan 16 12:13:21 -0500 2011

The model was loaded in Comment class, as you can see:

class Comment extends ActiveRecord\Model {
static $belongs_to = array(
array('posts')
);
}

I think it's a reflection bug. When I call Comment::delete(), PHPActiveRecord is trying to run AdminController::verify_not_readonly() instead of Comment::verify_not_readonly().

--- EDIT ---

Ah, I undestood now and it's working. I'm currently using:

function deleteComment($param)
{
$comment = Comment::find_by_id($param->id);
$comment->delete();
exit;
}

Thank you!

Jono B Mon Jan 17 14:18:27 -0500 2011

You are welcome.

If you are finding by ID, then you can also just do:

$comment = Comment::find($param->id);
$comment->delete();
exit;

(1-3/3)