CodeIgniter Forums
DataMapper 1.6.0 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: DataMapper 1.6.0 (/showthread.php?tid=11358)



DataMapper 1.6.0 - El Forum - 03-31-2009

[eluser]Oblique[/eluser]
>I think you you are over-complicating something unnecessarily.
Consider this as my favourite activity. )

Thank you for reasonable answer, i think it'll help.


DataMapper 1.6.0 - El Forum - 04-07-2009

[eluser]tdktank59[/eluser]
Not sure how self relations work in the new version.

Heres my table:
Quote:Members
- id
- sid
- name
- created_on
- parent_member_id

I want to be able to relate parent_member_id to id so I can set the parent member account.

Code:
class Member extends DataMapper
{
    var $table = 'members';

    var $has_many = array(  "problems", );
// Need to relate to itself. (parent_member_id to id)

    var $validation = array(
        array(
            'field' => 'sid',
            'label' => 'Member SID',
            'rules' => array('trim', 'min_length' => 2, 'max_length' => 255)
        ),
        array(
            'field' => 'name',
            'label' => 'Members Full Name',
            'rules' => array('trim')
        )
    );

    /**
     * Constructor
     *
     * Initialize DataMapper.
     */
    function Member()
    {
        parent::DataMapper();
    }

    // --------------------------------------------------------------------

}



DataMapper 1.6.0 - El Forum - 04-07-2009

[eluser]OverZealous[/eluser]
Code:
$has_one = array(
    // Child's side of the self relationship
    'parent_member' => array(
        // parent_member is really just a 'member'
        'class' => 'member'
    );
);

$has_many = array(
    // Parent's side of the self relationship
    'member' => array(
        // The parent is joined as 'parent_member'
        'other_field' => 'parent_member'
    );
);

To access the parent:
Code:
$member = new Member();
$member->get_by_id($this->input->post('id'));
$parent = $member->parent_member->get();

To access the children:
Code:
$children = $member->member->get();
foreach($children->all as $child) {
    ...
}

Saving:
Code:
$member->save_parent_member($parent);
// OR:
$member->save(array(
    'parent_member' => $parent
));

// Saving children onto the parent
$parent->save_member($children->all);

// etc.



DataMapper 1.6.0 - El Forum - 04-09-2009

[eluser]tdktank59[/eluser]
Thanks


DataMapper 1.6.0 - El Forum - 04-12-2009

[eluser]aman_tuladhar[/eluser]
$u = new User();
$u->get_where( array('email' => 'fred@Smith.com') );

$u->package->get(); <-- Something wrong here with this method

echo $u->package->title;



I keep getting this error

A Database Error Occurred

Error Number: 1054

Unknown column 'packages.*' in 'field list'

SELECT `packages`.`*` FROM (`packages`) LEFT JOIN `packages_users` ON `packages`.`id` = `packages_users`.`package_id` LEFT JOIN `users` ON `users`.`id` = `packages_users`.`user_id` WHERE `users`.`id` = 1


DataMapper 1.6.0 - El Forum - 04-12-2009

[eluser]Junior_Coder[/eluser]
Good Job...

Well done... Wink


DataMapper 1.6.0 - El Forum - 04-12-2009

[eluser]OverZealous[/eluser]
@aman_tuladhar

If you read the (original) DataMapper manual, you will see that it explains that problem in detail on the troubleshooting page, using the exact error you show.


DataMapper 1.6.0 - El Forum - 04-12-2009

[eluser]aman_tuladhar[/eluser]
ahh... I see
Thanks a Lot


DataMapper 1.6.0 - El Forum - 04-14-2009

[eluser]camporter1[/eluser]
I'm having difficulty understanding how we do self referencing. In the examples in the docs, it's assumed there are different categories to work with for models that are self referenced. What about situations where there is no way to distinguish between one record and another?

If anyone has examples for doing this, that would be great. Otherwise, I'll just write a specific part of my application without DataMapper, which might be a problem...


Thanks.


DataMapper 1.6.0 - El Forum - 04-14-2009

[eluser]OverZealous[/eluser]
@camporter1

You should look at my extended version of DM. It doesn't change the way existing DM code is written, but it provides a lot of new features, including much more powerful self-references. I don't have as nice of documentation, but I did try to include some examples.

You can view and download the latest version from here. It is a drop-in replacement for DM.

Please give it a try, and you can leave feedback for me here, or through a private message.