CodeIgniter Forums
DataMapper 1.6.0 - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Libraries & Helpers (
+--- Thread: DataMapper 1.6.0 (/showthread.php?tid=11358)

DataMapper 1.6.0 - El Forum - 03-31-2009

>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

Not sure how self relations work in the new version.

Heres my table:
- 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.

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(
            'field' => 'sid',
            'label' => 'Member SID',
            'rules' => array('trim', 'min_length' => 2, 'max_length' => 255)
            'field' => 'name',
            'label' => 'Members Full Name',
            'rules' => array('trim')

     * Constructor
     * Initialize DataMapper.
    function Member()

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


DataMapper 1.6.0 - El Forum - 04-07-2009

$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:
$member = new Member();
$parent = $member->parent_member->get();

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

// OR:
    'parent_member' => $parent

// Saving children onto the parent

// etc.

DataMapper 1.6.0 - El Forum - 04-09-2009


DataMapper 1.6.0 - El Forum - 04-12-2009

$u = new User();
$u->get_where( array('email' => '[email protected]') );

$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

Good Job...

Well done... Wink

DataMapper 1.6.0 - El Forum - 04-12-2009


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

ahh... I see
Thanks a Lot

DataMapper 1.6.0 - El Forum - 04-14-2009

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...


DataMapper 1.6.0 - El Forum - 04-14-2009


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.