Welcome Guest, Not a member yet? Register   Sign In
(Datamapper) One-to-Many Self Relationships [SOLVED]
#1

[eluser]Empu[/eluser]
Hi...

I have a problem with a one-to-many self relationships

How to describe a model for the table:
Code:
`id` int(5) unsigned NOT NULL AUTO_INCREMENT,
`parent_id` int(5) unsigned DEFAULT NULL,
`name` varchar(255) NOT NULL
parent_id is nullable

I tried with the code:
Code:
/* model */
class Organization extends DataMapper {

    var $table = 'organizations';
    var $has_one = array(
    'parent' => array(
        'class' => 'organization',
        'other_field' => 'organization',
        'join_self_as' => 'parent'
    ));
    var $has_many = array(
    'organization' => array(
        'other_field' => 'parent'
    )
    );

/* controller */
$org = new Organization();
$org->include_related('parent', array('name'));
$list = $org->get();
but it appears an error
Quote:Fatal error: Cannot use object of type Organization as array in Z:\htdocs\application\libraries\datamapper.php on line 2817

I tried looking in the manual, but could not find guides for it.

Thanks for helping Smile

Note: im using CI2, Datamapper1.8.1 and HMVC.


Messages In This Thread
(Datamapper) One-to-Many Self Relationships [SOLVED] - by El Forum - 08-08-2011, 06:37 PM
(Datamapper) One-to-Many Self Relationships [SOLVED] - by El Forum - 08-09-2011, 04:08 AM
(Datamapper) One-to-Many Self Relationships [SOLVED] - by El Forum - 08-09-2011, 05:27 AM
(Datamapper) One-to-Many Self Relationships [SOLVED] - by El Forum - 08-10-2011, 05:28 AM
(Datamapper) One-to-Many Self Relationships [SOLVED] - by El Forum - 08-10-2011, 05:49 AM
(Datamapper) One-to-Many Self Relationships [SOLVED] - by El Forum - 08-10-2011, 05:55 AM
(Datamapper) One-to-Many Self Relationships [SOLVED] - by El Forum - 08-10-2011, 05:59 AM



Theme © iAndrew 2016 - Forum software by © MyBB