Welcome Guest, Not a member yet? Register   Sign In
stuck on codeigniter and datamapper relationships
#1

[eluser]Unknown[/eluser]
I have a one to many relationship between resumé and qualification. but i cant get it working with datamapper- i have called on model qualification and the other Mresume (i have a controller named resume)

Code:
class Mresume extends DataMapper {
     var $has_many = array(
        'qualification' => array('join_self_as'=>'resume',
                                  'class'=>'Qualification'
                                 )
                        );


class Qualification extends DataMapper {

    var $has_one = array(
        'mresume' => array(
                        'join_other_as'=>'resume','class'=>'Mresume')
    );
this is there error i get->

Code:
Unable to save the qualification relationship: The related object was not saved.


I have a foreign key in the qualifications table resume_id, am stuck on this.. tried multiple combinations but the documentation is clear!
#2

[eluser]WanWizard[/eluser]
I assume your models in itself work? So no issues with model -> table mappings?
Code:
// check this first
$m = new Mresume();
$m->get();

$q = new Qualification();
$q->get();

Then, your models should look like
Code:
class Mresume extends DataMapper {

    var $has_many = array(
        'qualification' => array(
            'join_other_as' => 'resume'  // join key in the OTHER model
        )
    );
}

class Qualification extends DataMapper {

    var $has_one = array(
        'mresume' => array(
            'join_self_as'=>'resume'  // join key in THIS model
        )
    );
}




Theme © iAndrew 2016 - Forum software by © MyBB