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

[eluser]Empu[/eluser]
That was my mistake, does not read the manual carefully.

Now the databases structure to be like this,

Code:
`id` int(5) unsigned NOT NULL AUTO_INCREMENT,
`holding_id` int(5) unsigned DEFAULT NULL,
`name` varchar(255) NOT NULL

and the model & controller to be like this,

Code:
/* model */
class Organization extends DataMapper {

    var $table = 'organizations';
    var $has_one = array(
    'holding' => array(
        'class' => 'organization',
        'other_field' => 'organization'
    ));
    var $has_many = array(
    'organization' => array(
        'other_field' => 'holding'
    )
    );
// ...


/* controller */
$org = new Organization();
$org->include_related('holding', array('name'));
$list = $org->get();

As you say, it's work fine.

Thanks so much...


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