Containable relations reset

View: New views
4 Messages — Rating Filter:   Alert me  

Containable relations reset

by lightglitch :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hi,

I'm having an error using Containable, my problem is already describe
in https://trac.cakephp.org/ticket/4988 but the explanation of the
problem is not very clear.

So if we have the models:

1 - Node hasMany NodeTemplate
2 - NodeTemplate HasMany TextContent, AssetContent


 When executing the following code:

        pr($this->Node->NodeTemplate->hasMany);
        $this->Node->find('first',array(
                                    'contain'=>array(
                                            'NodeTemplate' => array(
 
'TextContent'=>array('fields'=>array('id'))
                                                    )
                                        )
                                ));
        pr($this->Node->NodeTemplate->hasMany);


The hasMany NodeTemplate break and looses the connection to
AssetContent.

After some debugging I did found out that the problem is in the
configuration of the TextContent in the contain.

If you try:

        pr($this->Node->NodeTemplate->hasMany);
        $this->Node->find('first',array(
                                    'contain'=>array(
                                            'NodeTemplate' => array(
                                                        'TextContent'
                                                    )
                                        )
                                ));
        pr($this->Node->NodeTemplate->hasMany);

OR

        pr($this->Node->NodeTemplate->hasMany);
        $this->Node->find('first',array(
                                    'contain'=>array(
                                            'NodeTemplate' => array(
 
'TextContent'=>array('OtherModel')
                                                    )
                                        )
                                ));
        pr($this->Node->NodeTemplate->hasMany);


It works ok.

if you use any parameter that is not a associated Model name like
fields, conditions, order, etc it doesn't work and breaks the
associations of the NodeTemplate by losing the one that is not used in
the contain.

Can anyone confirm this behavior? I'm using 1.2.5 version of cake.

Thx in advance.







--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@...
To unsubscribe from this group, send email to cake-php+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Containable relations reset

by John Andersen-6 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Using 1.2.5 too, can't recreate the issue.

User hasMany Author hasMany Article, Ebook
[code]
      debug($this->User->hasMany);
      debug(
      $this->User->find('first',array(
         'contain'=>array(
            'Author' => array(
               'Article' => array('fields' => array('id') )
            )
         )
      ))
      );
      debug($this->User->hasMany);
[/code]

Shows the same state of hasMany before and afther the find.

Please show the code that defines how your models are related!

The ticket is closed as fixed!
Enjoy,
   John

On Nov 3, 10:37 pm, lightglitch <mario.ffra...@...> wrote:

> Hi,
>
> I'm having an error using Containable, my problem is already describe
> inhttps://trac.cakephp.org/ticket/4988but the explanation of the
> problem is not very clear.
>
> So if we have the models:
>
> 1 - Node hasMany NodeTemplate
> 2 - NodeTemplate HasMany TextContent, AssetContent
>
>  When executing the following code:
>
>         pr($this->Node->NodeTemplate->hasMany);
>         $this->Node->find('first',array(
>                                     'contain'=>array(
>                                             'NodeTemplate' => array(
>
> 'TextContent'=>array('fields'=>array('id'))
>                                                     )
>                                         )
>                                 ));
>         pr($this->Node->NodeTemplate->hasMany);
>
> The hasMany NodeTemplate break and looses the connection to
> AssetContent.
>
> After some debugging I did found out that the problem is in the
> configuration of the TextContent in the contain.
>
> If you try:
>
>         pr($this->Node->NodeTemplate->hasMany);
>         $this->Node->find('first',array(
>                                     'contain'=>array(
>                                             'NodeTemplate' => array(
>                                                         'TextContent'
>                                                     )
>                                         )
>                                 ));
>         pr($this->Node->NodeTemplate->hasMany);
>
> OR
>
>         pr($this->Node->NodeTemplate->hasMany);
>         $this->Node->find('first',array(
>                                     'contain'=>array(
>                                             'NodeTemplate' => array(
>
> 'TextContent'=>array('OtherModel')
>                                                     )
>                                         )
>                                 ));
>         pr($this->Node->NodeTemplate->hasMany);
>
> It works ok.
>
> if you use any parameter that is not a associated Model name like
> fields, conditions, order, etc it doesn't work and breaks the
> associations of the NodeTemplate by losing the one that is not used in
> the contain.
>
> Can anyone confirm this behavior? I'm using 1.2.5 version of cake.
>
> Thx in advance.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@...
To unsubscribe from this group, send email to cake-php+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Containable relations reset

by John Andersen-6 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


DISREGARD, just saw the real issue, not at the User hasMany, but at
the Author hasMany!
Yes, I see the same problem!
Enjoy,
   John

On Nov 4, 8:47 am, John Andersen <j.andersen...@...> wrote:
> Using 1.2.5 too, can't recreate the issue.
>
> User hasMany Author hasMany Article, Ebook
[snip]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@...
To unsubscribe from this group, send email to cake-php+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Containable relations reset

by Marc-123 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I updated the ticket with a test to prove your issue.

On 4 nov, 07:49, John Andersen <j.andersen...@...> wrote:

> DISREGARD, just saw the real issue, not at the User hasMany, but at
> the Author hasMany!
> Yes, I see the same problem!
> Enjoy,
>    John
>
> On Nov 4, 8:47 am, John Andersen <j.andersen...@...> wrote:> Using 1.2.5 too, can't recreate the issue.
>
> > User hasMany Author hasMany Article, Ebook
>
> [snip]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@...
To unsubscribe from this group, send email to cake-php+unsubscribe@...
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---