Welcome Guest, Not a member yet? Register   Sign In
DMZ 1.7.1 (DataMapper OverZealous Edition)
#91

[eluser]Atas[/eluser]
Hello, DataMapper OverZealous Edition is great for me. But i have a question.
Can i set the primary key field name?. I have a lot of tables that primary key field name is "xxx_id". And i don't want to change it to "id".

I want to do something like this:

Code:
class Test extends DataMapper {
    
    var $table = 'testing';
    var $pk_filedname = 'test_id'; //<----

    function __construct($id = NULL)
    {
        parent::__construct($id);
    }
}

is this possible ?

Thanks.
#92

[eluser]OverZealous[/eluser]
@Atas

No. DMZ requires certain concessions in the database design.

Also, this is clearly stated in the manual.
#93

[eluser]Atas[/eluser]
Ok,

I am going to rename my Primary Keys...

Thanks!
#94

[eluser]Mareshal[/eluser]
I have one question, and please don't send me to read the manual.

I have one parent table, and 4 other child tables. One field from my parent is present in the other 4 child tables. Is there any way I can do this: update only the main parent table and all child table will get updated automatically?
#95

[eluser]OverZealous[/eluser]
@Mareshal
No. Write a custom method on the parent table's model, or override the save function on the parent table:
Code:
class Parent extends DataMapper {
    function save($object = '', $related_field = '') {
        $needs_update = ($this->shared_field === $this->stored->shared_field);
        $ret = parent::$save();
        if($need_update && $ret) {
            if($this->other_object->get()->exists()) {
                $this->other_object->shared_field = $this->shared_field;
                $this->other_object->save();
            }
            // repeat for each object
        }
        return $ret;
    }
}

You may need to add in special code to check for new objects. This is just an example, so don't take it as gospel.
#96

[eluser]Atas[/eluser]
Hello, i have the following models and tables:

CREATE TABLE `provincia` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`nombre` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;

Code:
class Provincia extends DataMapper {
    
    var $table = 'provincia';
    var $has_many = array("localidad");
    
    function __construct($id = NULL)
    {
        parent::__construct($id);
    }
    
}

CREATE TABLE `localidad` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`nombre` varchar(255) DEFAULT NULL,
`provincia_id` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;

Code:
class Localidad extends DataMapper {
    
    var $table = 'localidad';

    function __construct($id = NULL)
    {
        parent::__construct($id);
    }
    
}

I am triying to get all "localidades" by "provincia" but an error message appears saying "DataMapper Error: 'provincia' is not a valid parent relationship for Localidad. Are your relationships configured correctly?"

I don't know what i am doing wrong.

Provincia is State and Localidad is like City.

Sorry my english, i am learning...

Thanks...
#97

[eluser]OverZealous[/eluser]
See item #4 in the Troubleshooting guide.
#98

[eluser]Atas[/eluser]
Oh, sorry, it was in the troubleshooting. :red:

I had to update mysql_driver.php too.

Thanks.
#99

[eluser]NachoF[/eluser]
Im a little confused on how should I get this done

I have Projects which have many Stages and each stage has one Region, Function, and Organization.

I want to save it all at once cause its all coming from the same form. When you create the project you also create the first stage for it
Code:
if($project->save(array($stage, $region, $function, $organization)))
                    {
                            $this->session->set_flashdata('success', 'Project Created');
                            redirect("Welcome");
                    }

I know this code wont work cause regions and functions arent related to projects but I just wanted to show it so that maybe someone could have an idea on how could i get this done

[eluser]cahva[/eluser]
I upgraded DMZ from 1.6.2 to 1.7.1.

Just wanted to inform that if someone else has done the same.

Before DMZ 1.7.x there was no built-in way to localize labels so I did it this way:
Code:
class Customer Extends DataMapper {
    
    var $validation;
    var $has_one = array('customer','country');

    function __construct()
    {
        parent::__construct();
        $this->_set_validation();
    }

    function _set_validation()
    {
        $this->validation = array(
            'name' => array(
                'label' => lang('account.name'),
                'rules' => array('required','trim','min_lenght' => 3,'max_lenght' => 255)
            )
            
            ...
            
            'confirm_password' => array(
                'label' => lang('account.confirm_password'),
                'rules' => array('required', 'encrypt', 'matches' => 'password', 'min_length' => 3, 'max_length' => 40),
                'type' => 'password'
            )
        );
    }
}

This way of doing it messes up the validation in the new version so be sure to update your models to the new localization system(which is great btw!).

The problem with my previous approach was that if updating existing customer, the validation would fail because not defining confirm_password. For example:
Code:
$customer = new Customer();
$customer->get_by_name('cahva');
$customer->name = 'Cahvaaaa';
$customer->save();
That failed with 1.7.1 but not the earlier 1.6.2 version..

So if you are upgrading from earlier version and done something similar to get validation localized before, be sure to update your models.

EDIT: Hmm.. Could it be that using parent::__construct() before the _set_validation could have caused this behaviour?? Maybe that parent::__construct() was not needed anyway.. I have probably left it there by accident.




Theme © iAndrew 2016 - Forum software by © MyBB