ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

[Deprecated] DMZ 1.6.2 (DataMapper OverZealous Edition)

November 23, 2009 11:54pm

Subscribe [46]
  • #466 / May 04, 2010 8:03am

    Wazzu

    27 posts

    Advanced Relationship

    Hi all. I’m not able to understand how advanced relationships work.
    I’ve read user guide and made tests, but I can’t understand how field names are used.

    This is my sample case:
    - table users(id, name)
    - table quotes(id, client_id, worker_id)
    - user model and quote model

    One user (worker_id) can create a new quote for other user (client_id).
    ‘worker_id’ and ‘client_id’ are in fact ids from users table.

    How should I make relationships? This is what I’ve done:

    class Quote extends DataMapper {
      var $has_many = array(
            'client_id' => array('class' => 'user','other_field' => 'client'),
            'worker_id' => array('class' => 'user','other_field' => 'worker')
      );
    }
    class User extends DataMapper {
      var $has_one = array(
        'client' => array('class' => 'quote', 'other_field' => 'client_id'),
        'worker' => array('class' => 'quote', 'other_field' => 'worker_id')
      );
    }

    Is that right? And from my controller, how should I populate this? I want to get something like this:

    <?php
    $q = new Quote($id);
    
    $q->client->get();
    echo $q->client->name;
    
    $q->worker->get();
    echo $q->worker->name;
    ?>

    Please, help me understanding this relationships.
    Thanks all

  • #467 / May 04, 2010 8:52am

    OverZealous

    1030 posts

    @Wazzu

    Please post in the new forum.  DMZ 1.6 has been deprecated for a while now.

    You are more likely to get answers there.

  • #468 / May 04, 2010 12:32pm

    Wazzu

    27 posts

    Thanks, Phil.
    I posted here because of the version I use.
    I’ll post there anyway.

  • #469 / Aug 19, 2010 5:21am

    7amza

    78 posts

    sorry i posted it here the reply is here
    http://ellislab.com/forums/viewthread/149388/P580/#789462

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases