Welcome Guest, Not a member yet? Register   Sign In
[Deprecated] DMZ 1.5.3 (DataMapper OverZealous Edition)

[eluser]OverZealous[/eluser]
[quote author="mcnux" date="1251469051"]Rubbish this is me. Completely forgot I had overridden delete() in an extension to allow for deleting after relationships are removed. Sorry my bad!![/quote]

Ach! If I drank, I'd say you owe me a beer. :-)

I've been staring at the code, and it's almost 5:30 in the morning here. :-P

I should mention that I think I found a different bug when deleting just the relationship for self-referencing, ITFK relationships. It only occurs if you delete the relationship from one side — meaning, deleting $parent->delete($child) might have the error, but $child->delete($parent) won't. (Or vice-versa, it depends on which object is the ITFK.)

I have a fix in place for that, but I'm not going to be able to get it out right away. The work around for now is to swap the items if you see the bug.

All right, I think I'm done for...

[eluser]mcnux[/eluser]
sorry :red:

[eluser]PoetaWD[/eluser]
I am having a problem with a Advanced Relationship:

There are 2 model: profile and document

Each profile can have many documents, but only one CPF and RG (those are the most important documents here in Brazil)

Model 1: The Profile

Code:
class Profile extends DataMapper {

    var $has_one = array('ptratamento',
                             'cpf' => array(
                                'class' => 'document',
                                   'other_field' => 'dcpf'
                              ),
                               'rg' => array(
                                'class' => 'document',
                                   'other_field' => 'drg'
                               )
                        );
    
    var $has_many = array('endereco', 'document');

Model 2: The Document

Code:
<?php
class Document extends DataMapper {

    var $has_one = array('tipodocumento', 'profile');    
    var $has_many = array(
        'dcpf' => array(
            'class' => 'profile',
            'other_field' => 'cpf'
        ),
        'drg' => array(
            'class' => 'profile',
            'other_field' => 'rg'
        )
    );

The Controller:

Code:
if($this->input->post('stCPF') != '')
            {
                $cpf = new Document();
                $cpf->stNumero = $this->input->post('stCPF');
                
                $obj->save($cpf, 'cpf');
                
                                
            }
            
            if($this->input->post('stRG') != '')
            {
                $rg = new Document();
                $rg->stNumero = $this->input->post('stRG');
                
                $obj->save_rg($rg);
                
                
            }

The database:

Code:
CREATE TABLE IF NOT EXISTS `documents` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `stNome` varchar(200) NOT NULL,
  `stNumero` varchar(200) NOT NULL,
  `dtEmissao` varchar(200) NOT NULL,
  `stOrgaoEmissor` varchar(200) NOT NULL,
  `stMascara` varchar(200) NOT NULL,
  `stObservacoes` varchar(200) NOT NULL,
  `isAtivo` tinyint(1) NOT NULL DEFAULT '1',
  `rg_id` bigint(20) NOT NULL,
  `cpf_id` bigint(20) NOT NULL,
  `endprincipal_id` bigint(20) NOT NULL,
  `created` datetime NOT NULL,
  `updated` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=36 ;

The problem is that those documents are not being saved....

[eluser]OverZealous[/eluser]
First off, you cannot set In-table foreign keys to NOT NULL. They must allow NULL, or they won't save.

This is most likely your problem.

I also don't think you've set up your models correctly. This doesn't appear to make sense:
Code:
doc type | doc count | profile count
---------+-----------+----------------
   rg    |    1      |      N
   cpf   |    1      |      N
  other  |    N      |      1 <---- ???

The same document be associated with multiple profiles for rg and cpf types, but for all others, only associated with a single profile? It might be exactly what you meant, but it appears to be a mistake.

You might have meant to have $has_one relationships on rg and cpf, or you might have meant $has_many on other.

[eluser]NachoF[/eluser]
Hey Phil.... I was wondering what editor do you use??.... Im looking for an editor that can give me dropdown help of available attributes and methods for classes... mostly Datamapper classes and html helpers... any ideas?... I just tried Eclipse but with a Datamapper class doesnt seem to work.. also, its very slow... I have been using Visual Studio with asp.net MVC lately and code editing is really a breeze.

[eluser]OverZealous[/eluser]
@NachoF
I use Aptana Studio. Built in support for PHP, many JavaScript frameworks (including dojo, prototype, and jquery).

However, it is basically Eclipse, so it may not work for you. The DataMapper class is too big to edit directly, at any rate. You might have noticed I include a "src" directory. I've broken DMZ into several, well-grouped parts. I can edit these independently, and then I run build.php to convert them into datamapper.php.

I work on a Mac Pro, and the last time I used VS was about Windows 98. Smile

[eluser]PoetaWD[/eluser]
Like this ?

Code:
`rg_id` bigint(20) DEFAULT NULL,
  `cpf_id` bigint(20) DEFAULT NULL,

Still not working...

If I save the object first it will give me a error:

Code:
if($this->input->post('stCPF') != '')
            {
                $cpf = new Documento();
                $cpf->stNumero = $this->input->post('stCPF');
                
                $cpf->save();
                $obj->save($cpf, 'cpf');                                            
            }

Error:

Code:
A Database Error Occurred

Error Number: 1054

Unknown column 'dcpf_id' in 'where clause'

SELECT * FROM (`documentos_pfisicas`) WHERE `dcpf_id` = 48 AND `cpf_id` = 37

Explanation of my code:

Each user MUST have 2 documents: CPF and RG
But they can have more documents like: drivers license, professional registry...

I could do this in some other way... but I want to understand how this is done...

[eluser]OverZealous[/eluser]
@Poetawd

You've got something set up wrong. You've got the columns rg_id and cpf_id on the documents table, but those need to be on the profiles table. The document object isn't even related to an object called "rg" or "cpf", it is instead related to an object called "drg" or "dcpf", respectively, and it is $has_many.

The ITFK is always stored on the table that has only one of the other object. It can never exist on an object that $has_many. DMZ doesn't even look for ITFKs on $has_many relationships.

I'm pretty sure you want to rewrite it like this:
Code:
class Document extends DataMapper {

    var $has_one = array(
        'tipodocumento',
        'profile',
        'dcpf' => array(
            'class' => 'profile',
            'other_field' => 'cpf'
        ),
        'drg' => array(
            'class' => 'profile',
            'other_field' => 'rg'
        )
    );
    var $has_many = array();

And then add "rg_id" and "cpf_id" to the Profiles table.

FYI: DMZ assumes you want to store the relationship on the documents_profiles join table (in Portuguese, of course ;-) ), because it couldn't find the column "cpf_id" on the Profiles table.

[eluser]PoetaWD[/eluser]
Great !

It works ! Now i understand !

Just one more question, how to access those relationships ? (please poitn me the right page at the manual

Code:
$p = new Profile();

$p->where('name', 'Fred Smith')->get();

$p->CPF->get();     //???????????????????

echo '<p>' . $p->cpf->stNumber . '</p>';

is that correct ? I havent tryed,,,

[eluser]OverZealous[/eluser]
[quote author="PoetaWD" date="1251875679"]is that correct ? I havent tryed,,,[/quote]

:lol:

Everyone is always so afraid. Yes that is correct. Trying never really hurts anything, though!

I always say, make a backup and just push the button. That's how I learn. (Of course, it's usually followed by OH *^&#@! Good thing I don't work for the military! :-P )

You can also get the data in one pass (with $has_one relationships), if you want to save a query. That looks something like this:

Code:
$p = new Profile();

$p->where('name', 'Fred Smith');
$p->include_related('cpf'); // include all of the CPF columns.
$p->get();

/* Or chain it, if you prefer:
$p->where('name', 'Fred Smith')
    ->include_related('cpf')
    ->get();
*/

// Notice that it is cpf_stNumber, not cpf->stNumber
echo '<p>' . $p->cpf_stNumber . '</p>';

You can include any object that has a single relationship, and as many of them as you want. It even works for entire result sets. In the example above, there is only one query processed on the server.




Theme © iAndrew 2016 - Forum software by © MyBB