Welcome Guest, Not a member yet? Register   Sign In
Problems with Relationships - DMZ 1.3.2 - HELP! ;]~
#1

[eluser]Ivan Augusto[/eluser]
Hello... I'm having problems with making many relationships.

My Tables:

Code:
TB_CLIENT
PK - id

TB_CONTACT
PK - id
FK - client_id

TB_TYPE1
FK - contact_id

TB_TYPE2
FK - contact_id

Client 1:N Contacts
Contact 1:1 Client
Contact 1:1 Type1
Contact 1:1 Type2

I'm trying to do this:

Code:
class Client extends DataMapper {
    
    var $table = "tb_client";
    var $has_many = array(
        'contact' => array(
            'class' => 'contact',
            'other_field' => 'id'
        )
    );

    function __contruct() {
        parent::__construct();    
    }
}

class Contact extends DataMapper {
    
    var $table = "tb_contact";
    var $has_one = array(
        'client' => array(
            'class' => 'client',
            'other_field' => 'client_id'
        ),
        'type1' => array(
            'class' => 'type1',
            'other_field' => 'contact_id'
        ),
        'type2' => array(
            'class' => 'type2',
            'other_field' => 'contact_id'
        ),
    );
    function __contruct() {
        parent::__construct();    
    }
}
class Type1 extends DataMapper {
    
    var $table = "tb_type1";
    var $has_one = array(
        'contact' => array(
            'class' => 'contact',
            'other_field' => 'contact_id'
        )
    );
    function __contruct() {
        parent::__construct();    
    }
}
class Type2 extends DataMapper {
    
    var $table = "tb_type2";
    var $has_one = array(
        'contact' => array(
            'class' => 'contact',
            'other_field' => 'contact_id'
        )
    );
    function __contruct() {
        parent::__construct();    
    }
}

and in Controller:

Code:
$client = new Client();
$contact = new Contact();
$type1 = new Type1();

if ($client->save(array($contact,$type1))) {
    echo 'Save';
} else {
    echo 'Error';
}

But always gives error! Someone help me please!
xD~

Thks a lot =D
[]s

ps.: sorry my bad english




Theme © iAndrew 2016 - Forum software by © MyBB