Welcome Guest, Not a member yet? Register   Sign In
Datamapper - delete(). Not sure if this is a bug or my ignorance
#1

[eluser]Unknown[/eluser]
Hi
I am using version 1.8 of the Datamapper ORM and it is fantastic. It has saved loads of time.

I think I have found a bug in the delete() function.

If in my model I specify the relationship between two objects in the simple way:

Code:
class Area extends DataMapper {
    
    // Insert related models that Area can have just one of.
    var $has_one = array();
    
    // Insert related models that Area can have more than one of.
    var $has_many = array('room', 'color');
}


When I try and delete the Area using
Code:
$myarea = new Area($id);
$myarea->delete();

I get an error from the Datamapper class on line 1929
Code:
$object = new $class();
(The code trys to create an object called "r".)

telling me that "r" is not an object. (r is the first letter in the has_many array string)
I have swapped things around and added other realtionships and it always gives me the error on the first letter of the string.

If I specify the relationship in a different order for example (color now first):

Code:
class Area extends DataMapper {
    
    // Insert related models that Area can have just one of.
    var $has_one = array();
    
    // Insert related models that Area can have more than one of.
    var $has_many = array('color','room');
}


I get an error from the same line saying:
telling me that "c" is not an object. (always the first letter of the first member of the array)

It appears that it is reading the first letter in the has_many array and trying to treat it as an object.

If however I specify the realtionship in the model in the "complete" way
eg:
Code:
class Area extends DataMapper {
    
    // Insert related models that Area can have just one of.
    var $has_one = array();
    
    // Insert related models that Area can have more than one of.
    var $has_many = array('room' => array(
                'class' => 'room'
            )
                                                );
}

The delete works no problem.

Not sure if this is a bug or simply that I am doing something wrong.
#2

[eluser]WanWizard[/eluser]
Are you sure you're using the latest version?

There has been some updates and fixes about 3 weeks ago to the code that converts a simple relationship definition (like you use) to an advanced definition (what you call the "complete" way), because that is the structure Datamapper uses internally.

I've tried to recreate it here using your example code, but it works fine with the latest version.




Theme © iAndrew 2016 - Forum software by © MyBB