Part of the EllisLab Network
   
10 of 90
10
DMZ 1.7.1 (DataMapper OverZealous Edition)
Posted: 24 March 2010 12:39 PM   [ Ignore ]   [ # 91 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1041
Joined  10-08-2008

@Atas

No.  DMZ requires certain concessions in the database design.

Also, this is clearly stated in the manual.

 Signature 

Phil DeJarnett
  OverZealous Creations, LLC

Profile
 
 
Posted: 24 March 2010 12:50 PM   [ Ignore ]   [ # 92 ]  
Grad Student
Avatar
Rank
Total Posts:  59
Joined  03-04-2008

Ok,

I am going to rename my Primary Keys…

Thanks!

 Signature 

?

Profile
 
 
Posted: 24 March 2010 04:57 PM   [ Ignore ]   [ # 93 ]  
Lab Assistant
RankRank
Total Posts:  287
Joined  06-18-2009

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?

Profile
 
 
Posted: 24 March 2010 05:03 PM   [ Ignore ]   [ # 94 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1041
Joined  10-08-2008

@Mareshal
No.  Write a custom method on the parent table’s model, or override the save function on the parent table:

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.

 Signature 

Phil DeJarnett
  OverZealous Creations, LLC

Profile
 
 
Posted: 24 March 2010 11:38 PM   [ Ignore ]   [ # 95 ]  
Grad Student
Avatar
Rank
Total Posts:  59
Joined  03-04-2008

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;

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;

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…

 Signature 

?

Profile
 
 
Posted: 24 March 2010 11:40 PM   [ Ignore ]   [ # 96 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1041
Joined  10-08-2008

See item #4 in the Troubleshooting guide.

 Signature 

Phil DeJarnett
  OverZealous Creations, LLC

Profile
 
 
Posted: 25 March 2010 12:24 AM   [ Ignore ]   [ # 97 ]  
Grad Student
Avatar
Rank
Total Posts:  59
Joined  03-04-2008

Oh, sorry, it was in the troubleshooting. red face

I had to update mysql_driver.php too.

Thanks.

 Signature 

?

Profile
 
 
Posted: 25 March 2010 08:43 AM   [ Ignore ]   [ # 98 ]  
Lab Assistant
RankRank
Total Posts:  200
Joined  04-02-2009

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

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

Profile
 
 
Posted: 26 March 2010 08:28 AM   [ Ignore ]   [ # 99 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  674
Joined  07-16-2008

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:

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:

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

Profile
 
 
Posted: 26 March 2010 01:49 PM   [ Ignore ]   [ # 100 ]  
Grad Student
Avatar
Rank
Total Posts:  94
Joined  06-13-2009

Quick question:

In the past, when I needed nested categories, I would just have a categories table and a column with parent_id. If the parent id was 0, then it mean it didn’t have a parent.

What’s a good way to achieve nested categories in DMZ? I imagine it has to do with self relationships. I’ve never needed a self relationship before, so can someone tell me: is it the right way to go for this particular problem?

Just point me in a direction.

Thanks.

Profile
 
 
   
10 of 90
10
 
‹‹ Twitter Search      Layouts and actions in CI ››