Friday, May 31, 2013

Contain with an associated plugin

I'm having difficulty getting containable to work when the contained model is in a plugin. Specifically, I have a Group model that is associated with a Users (CakeDC) plugin. Normally, you just prefix the plugin model name with the plugin name such as Users.User, but it seems that the Containable behavior can't deal with that. Specifically, I've tried

$this->set('group', $this->Group->find('first',
    array(
       'conditions' => array('Group.slug' => $slug),
       'fields'     => array(
                             'Group.id',
                             'Group.name',
                             'Group.slug',
                             'Group.description',
                         ),
                         'contain'    => array(
                             'Users.User' => array(
                                 'conditions' => array('Users.User.group_id' => 'Group.id'),
                                 'fields'     => array(
                                     'Users.User.id',
                                     'Users.User.username',
                                     'Users.User.slug',
                                     'Users.User.email',
                                     'Users.User.active',
                                     'Users.User.last_login',
                                 ),
                                 'order'      => array('Users.User.username' => 'asc'),
                             ),
                         ),
                    )
                ));


Unfortunately, that results in this error:

Error: UsersController could not be found.

I've also tried it without the "Users." prefix, but that yields the same error. I have this in my Group model:

public $hasMany = array(
            'User' => array(
                'className'    => 'Users.User',
                'foreignKey'   => 'group_id',
                'dependent'    => FALSE,
            )
        );


Can anyone tell me how to handle plugin models within a contain.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Re: Help in simple query!

@Dakota
I'm already setting the relation as below

class Student extends AppModel {
var $name = 'Student';
var $hasMany = array('StudentAttendance');

AND

class StudentAttendance extends AppModel {
    var $name = 'StudentAttendance';
    var $belongsTo = 'Student';


On Thursday, May 30, 2013 8:26:28 AM UTC+2, Dakota wrote:
That would be the expected result for that query. You aren't including the 'SudentAttendance' model in your query. Looking how to use Containable, or custom join. You don't say what kind of relation there is between StudentAttendance and Student. CakePHP can't guess what you are trying to do, you need to tell it (The guessing part is coming up in version 4 as part of the MRD featureset)

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Re: Help in simple query!

@Dr. Drijk @resting
Model names must be singular.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Re: how to change a drop down based on a previously selected drop down in cakephp

You´ll need some javascript for this, check jQuery and jQuery ajax

Em sexta-feira, 31 de maio de 2013 10h04min42s UTC-3, sneha kulkarni escreveu:
hi..
I am trying to change a drop down based on a previously selected drop down ... How i should achieve the same using CakePHP.
plz help

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

how to change a drop down based on a previously selected drop down in cakephp

hi..
I am trying to change a drop down based on a previously selected drop down ... How i should achieve the same using CakePHP.
plz help

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Thursday, May 30, 2013

Re: Foreach saveField fails

did you change id to CHAR(36) in mysql ?

you could 

alter table by adding a temporary 'newid' field 

$this->saveField('newid', $new);

once looks good remove id, rename newid to id, add indexes etc... 

or

UPDATE entries SET id = uuid();


Careful if you have related tables with foreign key, as those need to be updated as well..


Andras Kende


On May 30, 2013, at 11:38 AM, Advantage+ <movepixels@gmail.com> wrote:

I am switching up a table 'id' field and simple doing a find all, generate a UUID, and try to update the field foreach but all its doing is creating new empty records.
 
 
foreach($this->find('all') as $entry) {
                $new = String::uuid();
                $this->id = $entry['Entry']['id'];
                //debug($this->id);
                $this->saveField('id', $new);
}
 
If I remove the commented out debug() I get all the original id's but it simply not update the record.
 
Even tried $this->updateAll(array('Entry.id' => $new), array('Entry.id' => $entry['Entry']['id']));
 
But that does not seem to work eiter.
 
Any ideas?
 

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
--- 
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Re: dom pdf con cake php

Estimado una consulta, si yo quiero mostar en el pdf los datos de la tabla Alumnos, la cual contiene como campos, ID, NOMBRE, DIRECCION, TELEFONO, etc...
como tendria que llamar a estos campos para que se logren mostrar...

Saludos

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Foreach saveField fails

I am switching up a table 'id' field and simple doing a find all, generate a UUID, and try to update the field foreach but all its doing is creating new empty records.

 

 

foreach($this->find('all') as $entry) {

                $new = String::uuid();

                $this->id = $entry['Entry']['id'];

                //debug($this->id);

                $this->saveField('id', $new);

}

 

If I remove the commented out debug() I get all the original id's but it simply not update the record.

 

Even tried $this->updateAll(array('Entry.id' => $new), array('Entry.id' => $entry['Entry']['id']));

 

But that does not seem to work eiter.

 

Any ideas?

 

Re: User defined id

Set the 'type'  of the input to 'text;

echo $this->Form->input('id', array('type' => 'text'));


Jeremy Burns
Class Outfit

http://www.classoutfit.com

On 30 May 2013, at 14:04, Eros Zanchetta <eros.zanchetta@gmail.com> wrote:

Hi there,

I'm just starting a new project with Cakephp but I'm stuck with a very basic problem.

I have a "countries" table that looks like this:

CREATE TABLE `countries` (
 `id` varchar(7) NOT NULL DEFAULT '',
 `name` varchar(255) NOT NULL DEFAULT '',
 `description` varchar(255) NOT NULL DEFAULT '',
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


As you can see want to use a VARCHAR as primary key as I want to use a customized country code as primary key (e.g. FR-2013, DE-2010, ES-2010 etc), I also want users to be able to manually insert this code. I know using a non-numeric id is not recommended but I have my reasons.

Now, when I create a form to add data (I want users to be able to add new countries), the `id` field is automatically hidden, I could probably come up with a workaround but I was wondering if there a "proper" way to do it.

I also have other tables where I have a similar situation.

Thanks,
Eros

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Accelerate your ROI, Like these Businesses

  Cannot see this email? View in browser
 
Web Marketing Today
 
We're pleased to provide you — a Web Marketing Today subscriber — with this unique educational offer.
If you'd prefer not to receive any email communications from us, please unsubscribe your email address below.
May 30, 2013
 

Learn How these Small Businesses Accelerate their ROI

See how the Joe and Janette doubled revenue.
Joe and Janette had a new business and a newborn, but time and money were in short supply. By automating their marketing with Infusionsoft, the Gleasons' marketing spend dropped 87% and their revenue doubled...
» Watch the Video
See how Pam produced 40% more revenue with Infusionsoft
Pam was missing out on repeat business. With data scattered across multiple systems, Pam couldn't target her customers with specific offers. Once she got Infusionsoft, she got organized--and got to know her customer better. Now, her tailored promotions bring in more revenue. 40% more revenue...» Watch the Video
Be Infusionsoft's Next Case Study. Get our biggest discount of the year and exposure on the Infusionsoft Website.

Apply for the Infusionsoft
Case Study Program.

Participation is limited. Apply today.

 

Infusionsoft Headquarters:
1260 South Spectrum Blvd. Chandler, Arizona 85286 United States (866) 800-0004

 
Share: Twitter Facebook


Web Marketing Today®
518 28 Road, Suite B-203, Grand Junction, CO, 81501, U.S. 970-257-0606
Contact Us

Copyright © 2013 Web Marketing Today. All rights reserved.
Please do NOT reprint or host on your website without explicit permission.
 

 

If you do not wish to receive mail from us, please click here to unsubscribe .

User defined id

Hi there,

I'm just starting a new project with Cakephp but I'm stuck with a very basic problem.

I have a "countries" table that looks like this:

CREATE TABLE `countries` (
 `id` varchar(7) NOT NULL DEFAULT '',
 `name` varchar(255) NOT NULL DEFAULT '',
 `description` varchar(255) NOT NULL DEFAULT '',
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


As you can see want to use a VARCHAR as primary key as I want to use a customized country code as primary key (e.g. FR-2013, DE-2010, ES-2010 etc), I also want users to be able to manually insert this code. I know using a non-numeric id is not recommended but I have my reasons.

Now, when I create a form to add data (I want users to be able to add new countries), the `id` field is automatically hidden, I could probably come up with a workaround but I was wondering if there a "proper" way to do it.

I also have other tables where I have a similar situation.

Thanks,
Eros

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

How to insert looping checked box value into db?

This is my code and attached the format i need please check it.

INDEX.CTP

<div>
<?php echo $this->Form->Create('Schedule'); 
    $appday = array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
        $apptime = array('01:00','02:00','03:00','04:00','05:00','06:00','07:00','08:00','09:00','10:00','11:00','12:00','13:00','14:00','15:00','16:00','17:00','18:00','19:00','20:00','21:00','22:00','23:00');
     ?>
     <table>
      <tr><td></td>
        <?php  
        for($k=0; $k<23; $k++) {
            echo '<td>'.$apptime[$k].'</td>';
            }
            echo '</tr>'; 
        ?>
        </tr>
     <?php   
        for($i=0; $i<7; $i++) {
        echo '<tr><td>'.$appday[$i].'</td>';
            for($j=0; $j<23; $j++) {
     ?>
            <td>
            <?php
                echo $this->Form->checkbox($appday[$i].'.'.$apptime[$j],array('hiddenfield' =>false));
                ?>
            </td>
     <?php       }
            echo '</tr>';
        }
     ?>
     </table>
    <?php
    echo $this->Form->end('Submit');
    ?>
</div>

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Re: php cms and rewriteRule and cakephp routes

We use our own CMS with CakePHP websites (we're currently translating our own cms into a new cakephp cms.). We use the same structure as you, (app, lib, plugins, vendors, cms) and we don't do anything with the .htaccess files inside the cakephp part (we also use routes, but don't create a /cms route especially). We do have this inside our cms map in the .htaccess:
RewriteEngine On
RewriteBase /

RewriteRule ^(.*)/(.*)/(.*)/(.*)/(.*)/$ cms/?module=$1&page=$2&pagenumber=$3&get4=$4&get5=$5 [L]
RewriteRule ^(.*)/(.*)/(.*)/(.*)/$ cms/?module=$1&page=$2&pagenumber=$3&get4=$4 [L]
RewriteRule ^(.*)/(.*)/(.*)/$ cms/?module=$1&page=$2&pagenumber=$3 [L]
RewriteRule ^(.*)/(.*)/$ cms/?module=$1&page=$2 [L]
RewriteRule ^(.*)/$ cms/?module=$1 [L]

We can access our cms at websitename.com/cms. I hope something like this will also work for you!

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Re: Routes and multilanguage site

That worked! Thanks! 

I feel so stupid now haha. We tried so many things and in the maintime it would all have worked if we had just put that part below everything else.

Op donderdag 30 mei 2013 08:28:02 UTC+2 schreef Bogdan Soos het volgende:
Hi there,

Try changing the order, nothing is being routed after your first rule, at least move the first rule at the end, that should be your last rule.

Regards,
Bogdan.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Wednesday, May 29, 2013

Routes and multilanguage site

Hi there,

Try changing the order, nothing is being routed after your first rule, at least move the first rule at the end, that should be your last rule.

Regards,
Bogdan.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

Re: php cms and rewriteRule and cakephp routes

You should put the piwik folder inside your webroot/ folder. CakePHP directly serves any files inside webroot without parsing them through it's internal router.

On Monday, 20 May 2013 05:22:07 UTC+2, Mehrdad Dadkhah wrote:
hi

I have this folders in the host root:

app
lib
plugins
vendors
piwik

piwik is a php cms (just php no framework)

but this address (mySite.com/piwik) don't go to /piwik folder and
wan't to use rewriteRule and cakephp routes for it
I try lot of htaccess codes to resolve it but it didn't work
somthing like:

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteCond %{REQUEST_URI} !^/piwik/
   RewriteRule    ^piwik -    [L]
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]
</IfModule>

and ....

how can resolve this problem?

thanks in advance

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Re: Help in simple query!

That would be the expected result for that query. You aren't including the 'SudentAttendance' model in your query. Looking how to use Containable, or custom join. You don't say what kind of relation there is between StudentAttendance and Student. CakePHP can't guess what you are trying to do, you need to tell it (The guessing part is coming up in version 4 as part of the MRD featureset)

On Thursday, 30 May 2013 01:46:53 UTC+2, gonzela2006 wrote:
Hello,

I used the following code in "StudentAttendances" controller:

$students = $this ->StudentAttendance->Student-> find('all', array(
'conditions' => array(
'NOT' => array('StudentAttendance.date' => array($year.'-'.$month.'-'.$day))
),
'fields' => array('Student.id', 'Student.name'),
'order' => 'Student.name ASC'
));


On Wednesday, May 29, 2013 8:02:29 AM UTC+2, resting wrote:
It will be helpful if you show us what you had done to produce that error.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Re: Help in simple query!

Have to agree with Dr. Drijk to check on typos.
Is it StudentAttendances.date instead?

On Thursday, 30 May 2013 07:46:53 UTC+8, gonzela2006 wrote:
Hello,

I used the following code in "StudentAttendances" controller:

$students = $this ->StudentAttendance->Student-> find('all', array(
'conditions' => array(
'NOT' => array('StudentAttendance.date' => array($year.'-'.$month.'-'.$day))
),
'fields' => array('Student.id', 'Student.name'),
'order' => 'Student.name ASC'
));


On Wednesday, May 29, 2013 8:02:29 AM UTC+2, resting wrote:
It will be helpful if you show us what you had done to produce that error.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Re: php cms and rewriteRule and cakephp routes

thanks
I use it

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/piwik/*
RewriteRule ^$ app/webroot/ [L]
RewriteCond %{REQUEST_URI} !^/piwik/*
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>

and it's work ....

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

Re: Help in simple query!

Hello,

I used the following code in "StudentAttendances" controller:

$students = $this ->StudentAttendance->Student-> find('all', array(
'conditions' => array(
'NOT' => array('StudentAttendance.date' => array($year.'-'.$month.'-'.$day))
),
'fields' => array('Student.id', 'Student.name'),
'order' => 'Student.name ASC'
));


On Wednesday, May 29, 2013 8:02:29 AM UTC+2, resting wrote:
It will be helpful if you show us what you had done to produce that error.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Re: containable problem

I'm glad it worked. It always helps to use 'fields' in order to keep down the returned data to only those needed. Not only it's good for the database but it also helps you check the cake produced SQL against what you expect plus make more sense on the results to see what you want instead of everything (or a minimal set when you debug). The main model doesn't need you to add any 'id' fields or external keys but contain does, if you don't it won't fetch any data, so I'm always adding them in model as well to be on the safe side.

On Wednesday, May 29, 2013 10:46:11 PM UTC+3, Robert Gravel wrote:
So embarrassing. In my long list of associations School->User  was missing? Your code worked thanks a bunch..

Robert


--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Re: containable problem

So embarrassing. In my long list of associations School->User  was missing? Your code worked thanks a bunch..

Robert


On Wed, May 29, 2013 at 3:22 PM, Robert Gravel <rockbust@gmail.com> wrote:
John thank you but it seems to not be working. I was mistaken that your code is the same as my second example.
I have pasted your code:
when I input a date range of may27 - may 29, I am returned all associated models and no filtering on the Attendance model.
You can see both Attendance records returned when only one should be.

SELECT `Attendance`.`id`, `Attendance`.`created`, `Attendance`.`modified`, `Attendance`.`user_id`, `Attendance`.`program_id`, `Attendance`.`school_id` FROM `attendances` AS `Attendance` WHERE `Attendance`.`school_id` = (2)
1] => Array          (              [User] => Array                  (                      [id] => 119                      [group_id] => 2                      [username] => mdonohue                      [role] =>                       [password] => 1234                      [email] => bla@mail.com                      [phone] => 631-252-5790                      [cell_phone] =>                       [active] => 1                      [first_name] => Mikey                      [last_name] => Donohue                      [country] =>                       [address] => 12324 any street                      [city] => anycity                      [state] => NY                      [zip_code] => 11739                      [created] => 2011-12-14 16:53:33                      [modified] => 2011-12-14 21:45:24                      [about_me] =>                       [household_id] => 2                      [is_head] => 1                      [birthdate] => 1968-01-16                      [activated] => 0                      [activation_code] =>                       [school_id] => 2                      [name] =>                       [uniform_size] => 5                      [barcode] => 9375361                      [show_profile] => 0                      [photo] =>                       [photo_dir] =>                       [lead_source] =>                   )                [Household] => Array                  (                      [id] => 2                      [name] => mikey donohue                      [payment_token] =>                       [payment_type] =>                       [school_id] => 2                  )                [Attendance] => Array                  (                      [0] => Array                          (                              [id] => 185                              [created] => 2013-05-27                              [modified] => 2013-05-29 03:34:40                              [user_id] => 119                              [program_id] => 3                              [school_id] => 2                          )                        [1] => Array                          (                              [id] => 186                              [created] => 2013-05-26                              [modified] => 2013-05-29 03:35:06                              [user_id] => 119                              [program_id] => 3                              [school_id] => 2                          )                    )                [Photo] => Array                  (                  )                [News] => Array                  (                  )                [Eventregistration] => Array                  (                  )                [Rankforuser] => Array                  (                      [0] => Array                          (                              [id] => 524                              [created] => 2013-05-28                              [modified] => 2013-05-28                              [user_id] => 119                              [rank_id] => 28                              [program_id] => 3                              [school_id] => 2                              [current_rank] => 1                          )                    )                [Testregistration] => Array                  (                  )                [Trial] => Array                  (                      [0] => Array                          (                              [id] => 32                              [date] => 2012-01-15 09:35:00                              [reminder] => 1                              [reminder_date] => 2011-12-31 09:35:00                              [message] =>                               [created] => 2011-12-15 09:37:20                              [modified] => 2011-12-15 09:49:08                              [template_id] => 7                              [staff_id] => 2                              [user_id] => 119                              [school_id] => 2                          )                    )                [Usermembership] => Array                  (                      [0] => Array                          (                              [id] => 314                              [start_date] => 2013-06-01                              [end_date] => 2015-06-01                              [created] => 2013-05-28 19:35:19                              [modified] => 2013-05-28 19:35:19                              [status] => 1                              [user_id] => 119                              [program_id] => 3                              [school_id] => 2                              [downpayment] => 199                              [downpayment_due] => 2013-06-01                              [installment_number] => 24                              [installment_payment] => 150                              [installment_date] => 2013-06-01                              [total_due] => 3900                          )                    )                [Bill] => Array                  (                      [0] => Array                          (                              [id] => 1912                              [due_date] => 2013-06-01                              [description] => Membership 1/24                              [auto_pay] => 1                              [amount] => 150                              [amount_paid] => 0                              [payment_type] =>                               [payment_date] => 0000-00-00 00:00:00                              [payment_status] => 0                              [created] => 2013-05-28 19:35:19                              [user_id] => 119                              [school_id] => 2                              [eventregistration_id] => 0                              [testregistration_id] => 0                              [usermembership_id] => 314                          )  If I do not apply the conditions to the User model the containable and date work correctly but it returns all users with other school_id's

  [4] => Array ( [User] => Array ( [id] => 119 [group_id] => 2 [username] => mdonohue [role] => [password] => 1234 [email] => bla@mail.com [phone] => 631-252-5790 [cell_phone] => [active] => 1 [first_name] => Mikey [last_name] => Donohue [country] => [address] => 12324 any street [city] => anycity [state] => NY [zip_code] => 11739 [created] => 2011-12-14 16:53:33 [modified] => 2011-12-14 21:45:24 [about_me] => [household_id] => 2 [is_head] => 1 [birthdate] => 1968-01-16 [activated] => 0 [activation_code] => [school_id] => 2 [name] => [uniform_size] => 5 [barcode] => 9375361 [show_profile] => 0 [photo] => [photo_dir] => [lead_source] => ) [Attendance] => Array ( [0] => Array ( [id] => 185 [created] => 2013-05-27 [modified] => 2013-05-29 03:34:40 [user_id] => 119 [program_id] => 3 [school_id] => 2 ) ) [Usermembership] => Array ( [0] => Array ( [id] => 314 [start_date] => 2013-06-01 [end_date] => 2015-06-01 [created] => 2013-05-28 19:35:19 [modified] => 2013-05-28 19:35:19 [status] => 1 [user_id] => 119 [program_id] => 3 [school_id] => 2 [downpayment] => 199 [downpayment_due] => 2013-06-01 [installment_number] => 24 [installment_payment] => 150 [installment_date] => 2013-06-01 [total_due] => 3900 ) ) )





On Wed, May 29, 2013 at 2:27 PM, John <spiliot@gmail.com> wrote:
Are you sure you tried the code I proposed in my second message? If yes what is the error message or returned output like?

Your first example in the first message is different to what I wrote. What you were doing is to find all users then use their IDs to return results from the other tables (this is how contain works). First you asked containable to apply it to Attendance then on Usermembership and finally to the User model which would need User to be connected to the User model. This of course is not the case, it was failing and it was telling you why.


$this->User->find('all',
  array('contain' => array(
    'Attendance' => array(
      'conditions' => $cond
    ),
    'Usermembership',
    'User' => array(
      'conditions' => $cond2)
    )
  )
);

On your second example you are using Model::find wrong. It is defined as find(string $type = 'first', array $params = array()) (notice only two parameters) but you called it as find('all', array(<whatever>), array(<whatever)).  Of course it fails with three parameters (PHP should be telling you that).

My code is telling cake to
1. Get the proper filtered users as 'conditions' => cond2 are applied to the User model
2. Use the IDs of those users to return "contained" data from the other associated models ('contain' => ...)

If this is failing then your models are probably not properly associated or I'm overlooking something.



On Wed, May 29, 2013 at 11:35 AM, John <spi...@gmail.com> wrote:
What are your model associations?

Have you tried to break it down to one step at a time (no contained model then add one at a time) and have a look at the produced SQL?

I usually blindly add a 'recursive' = -1 clause in all find options when I use containable to keep things simple (unless it is needed otherwise of course).

If you can't get it to work with contain you can always use plain old SQL to get the proper results, no need to accept whatever cake is pulling out for you with its magic.



On Wednesday, May 29, 2013 5:43:21 PM UTC+3, Robert Gravel wrote:
Hi John, This was the exact code i tried in my second example. putting the condition for the current model seems to break the containable method and then all related models are returned. also the date search within the Attendance model also breaks.

There must be a way here I am not seeing.

I would hate to return all users and have to loop thru potentially thousands to rebuild the array.

Any other options?

Robert


On Wed, May 29, 2013 at 6:25 AM, John <spi...@gmail.com> wrote:
The message is telling you what is wrong, you are asking containable to contain the starting Model again

$users = $this->User->find('all',
  array(
    'conditions' => $cond2
  ),
  array(
    'contain' => array(
      'Attendance' => array(
        'conditions' => $cond
      ),
      'Usermembership'
    )
  )
);


I think there's the problem, make your code like this:

$users = $this->User->find('all',
  array(
    'conditions' => $cond2,

    'contain' => array(
      'Attendance' => array(
        'conditions' => $cond
      ),
      'Usermembership'
    )
  )
);


I always indent arrays inside finds to the extremes, especially if something is wrong because it helps to understand hierarchy and nesting better. You can always compact it to a single line if you think it's better later


On Wednesday, May 29, 2013 6:10:47 AM UTC+3, Robert Gravel wrote:
Hi experts,

I am having an issue with containable. I have no problems returning the proper records for Attendance condition but the database call will still return all users in database with empty attendance field.
I need to return only User.school_id that match admin's $session_school_id

tried this
$this->User->Behaviors->attach('Containable');
$from =  $this->data['User']['start_date']['year'] . "-" . $this->data['User']['start_date']['month'] . "-" . $this->data['User']['start_date']['day'];
 $to =  $this->data['User']['end_date']['year'] . "-" . $this->data['User']['end_date']['month'] . "-" . $this->data['User']['end_date']['day'];
$cond = array('Attendance.created BETWEEN ? AND ?' => array($from, $to), 'Attendance.school_id' => $session_school_id);
// return only school user
$cond2 = array('User.school_id' => $session_school_id);
$users = $this->User->find('all', array('contain' => array('Attendance' => array('conditions' => $cond), 'Usermembership', 'User' => array('conditions' => $cond2) )));

this gives me Warning (512): Model "User" is not associated with model "User"

and tried this

$users = $this->User->find('all', array('conditions' => $cond2), array('contain' => array('Attendance' => array('conditions' => $cond), 'Usermembership' )));

does not work either.

cake 1.3
Thank you
Robert

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+u...@googlegroups.com.
To post to this group, send email to cake...@googlegroups.com.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+u...@googlegroups.com.
To post to this group, send email to cake...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 


--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Re: containable problem

John thank you but it seems to not be working. I was mistaken that your code is the same as my second example.
I have pasted your code:
when I input a date range of may27 - may 29, I am returned all associated models and no filtering on the Attendance model.
You can see both Attendance records returned when only one should be.

SELECT `Attendance`.`id`, `Attendance`.`created`, `Attendance`.`modified`, `Attendance`.`user_id`, `Attendance`.`program_id`, `Attendance`.`school_id` FROM `attendances` AS `Attendance` WHERE `Attendance`.`school_id` = (2)
1] => Array          (              [User] => Array                  (                      [id] => 119                      [group_id] => 2                      [username] => mdonohue                      [role] =>                       [password] => 1234                      [email] => bla@mail.com                      [phone] => 631-252-5790                      [cell_phone] =>                       [active] => 1                      [first_name] => Mikey                      [last_name] => Donohue                      [country] =>                       [address] => 12324 any street                      [city] => anycity                      [state] => NY                      [zip_code] => 11739                      [created] => 2011-12-14 16:53:33                      [modified] => 2011-12-14 21:45:24                      [about_me] =>                       [household_id] => 2                      [is_head] => 1                      [birthdate] => 1968-01-16                      [activated] => 0                      [activation_code] =>                       [school_id] => 2                      [name] =>                       [uniform_size] => 5                      [barcode] => 9375361                      [show_profile] => 0                      [photo] =>                       [photo_dir] =>                       [lead_source] =>                   )                [Household] => Array                  (                      [id] => 2                      [name] => mikey donohue                      [payment_token] =>                       [payment_type] =>                       [school_id] => 2                  )                [Attendance] => Array                  (                      [0] => Array                          (                              [id] => 185                              [created] => 2013-05-27                              [modified] => 2013-05-29 03:34:40                              [user_id] => 119                              [program_id] => 3                              [school_id] => 2                          )                        [1] => Array                          (                              [id] => 186                              [created] => 2013-05-26                              [modified] => 2013-05-29 03:35:06                              [user_id] => 119                              [program_id] => 3                              [school_id] => 2                          )                    )                [Photo] => Array                  (                  )                [News] => Array                  (                  )                [Eventregistration] => Array                  (                  )                [Rankforuser] => Array                  (                      [0] => Array                          (                              [id] => 524                              [created] => 2013-05-28                              [modified] => 2013-05-28                              [user_id] => 119                              [rank_id] => 28                              [program_id] => 3                              [school_id] => 2                              [current_rank] => 1                          )                    )                [Testregistration] => Array                  (                  )                [Trial] => Array                  (                      [0] => Array                          (                              [id] => 32                              [date] => 2012-01-15 09:35:00                              [reminder] => 1                              [reminder_date] => 2011-12-31 09:35:00                              [message] =>                               [created] => 2011-12-15 09:37:20                              [modified] => 2011-12-15 09:49:08                              [template_id] => 7                              [staff_id] => 2                              [user_id] => 119                              [school_id] => 2                          )                    )                [Usermembership] => Array                  (                      [0] => Array                          (                              [id] => 314                              [start_date] => 2013-06-01                              [end_date] => 2015-06-01                              [created] => 2013-05-28 19:35:19                              [modified] => 2013-05-28 19:35:19                              [status] => 1                              [user_id] => 119                              [program_id] => 3                              [school_id] => 2                              [downpayment] => 199                              [downpayment_due] => 2013-06-01                              [installment_number] => 24                              [installment_payment] => 150                              [installment_date] => 2013-06-01                              [total_due] => 3900                          )                    )                [Bill] => Array                  (                      [0] => Array                          (                              [id] => 1912                              [due_date] => 2013-06-01                              [description] => Membership 1/24                              [auto_pay] => 1                              [amount] => 150                              [amount_paid] => 0                              [payment_type] =>                               [payment_date] => 0000-00-00 00:00:00                              [payment_status] => 0                              [created] => 2013-05-28 19:35:19                              [user_id] => 119                              [school_id] => 2                              [eventregistration_id] => 0                              [testregistration_id] => 0                              [usermembership_id] => 314                          )  If I do not apply the conditions to the User model the containable and date work correctly but it returns all users with other school_id's

  [4] => Array ( [User] => Array ( [id] => 119 [group_id] => 2 [username] => mdonohue [role] => [password] => 1234 [email] => bla@mail.com [phone] => 631-252-5790 [cell_phone] => [active] => 1 [first_name] => Mikey [last_name] => Donohue [country] => [address] => 12324 any street [city] => anycity [state] => NY [zip_code] => 11739 [created] => 2011-12-14 16:53:33 [modified] => 2011-12-14 21:45:24 [about_me] => [household_id] => 2 [is_head] => 1 [birthdate] => 1968-01-16 [activated] => 0 [activation_code] => [school_id] => 2 [name] => [uniform_size] => 5 [barcode] => 9375361 [show_profile] => 0 [photo] => [photo_dir] => [lead_source] => ) [Attendance] => Array ( [0] => Array ( [id] => 185 [created] => 2013-05-27 [modified] => 2013-05-29 03:34:40 [user_id] => 119 [program_id] => 3 [school_id] => 2 ) ) [Usermembership] => Array ( [0] => Array ( [id] => 314 [start_date] => 2013-06-01 [end_date] => 2015-06-01 [created] => 2013-05-28 19:35:19 [modified] => 2013-05-28 19:35:19 [status] => 1 [user_id] => 119 [program_id] => 3 [school_id] => 2 [downpayment] => 199 [downpayment_due] => 2013-06-01 [installment_number] => 24 [installment_payment] => 150 [installment_date] => 2013-06-01 [total_due] => 3900 ) ) )





On Wed, May 29, 2013 at 2:27 PM, John <spiliot@gmail.com> wrote:
Are you sure you tried the code I proposed in my second message? If yes what is the error message or returned output like?

Your first example in the first message is different to what I wrote. What you were doing is to find all users then use their IDs to return results from the other tables (this is how contain works). First you asked containable to apply it to Attendance then on Usermembership and finally to the User model which would need User to be connected to the User model. This of course is not the case, it was failing and it was telling you why.


$this->User->find('all',
  array('contain' => array(
    'Attendance' => array(
      'conditions' => $cond
    ),
    'Usermembership',
    'User' => array(
      'conditions' => $cond2)
    )
  )
);

On your second example you are using Model::find wrong. It is defined as find(string $type = 'first', array $params = array()) (notice only two parameters) but you called it as find('all', array(<whatever>), array(<whatever)).  Of course it fails with three parameters (PHP should be telling you that).

My code is telling cake to
1. Get the proper filtered users as 'conditions' => cond2 are applied to the User model
2. Use the IDs of those users to return "contained" data from the other associated models ('contain' => ...)

If this is failing then your models are probably not properly associated or I'm overlooking something.



On Wed, May 29, 2013 at 11:35 AM, John <spi...@gmail.com> wrote:
What are your model associations?

Have you tried to break it down to one step at a time (no contained model then add one at a time) and have a look at the produced SQL?

I usually blindly add a 'recursive' = -1 clause in all find options when I use containable to keep things simple (unless it is needed otherwise of course).

If you can't get it to work with contain you can always use plain old SQL to get the proper results, no need to accept whatever cake is pulling out for you with its magic.



On Wednesday, May 29, 2013 5:43:21 PM UTC+3, Robert Gravel wrote:
Hi John, This was the exact code i tried in my second example. putting the condition for the current model seems to break the containable method and then all related models are returned. also the date search within the Attendance model also breaks.

There must be a way here I am not seeing.

I would hate to return all users and have to loop thru potentially thousands to rebuild the array.

Any other options?

Robert


On Wed, May 29, 2013 at 6:25 AM, John <spi...@gmail.com> wrote:
The message is telling you what is wrong, you are asking containable to contain the starting Model again

$users = $this->User->find('all',
  array(
    'conditions' => $cond2
  ),
  array(
    'contain' => array(
      'Attendance' => array(
        'conditions' => $cond
      ),
      'Usermembership'
    )
  )
);


I think there's the problem, make your code like this:

$users = $this->User->find('all',
  array(
    'conditions' => $cond2,

    'contain' => array(
      'Attendance' => array(
        'conditions' => $cond
      ),
      'Usermembership'
    )
  )
);


I always indent arrays inside finds to the extremes, especially if something is wrong because it helps to understand hierarchy and nesting better. You can always compact it to a single line if you think it's better later


On Wednesday, May 29, 2013 6:10:47 AM UTC+3, Robert Gravel wrote:
Hi experts,

I am having an issue with containable. I have no problems returning the proper records for Attendance condition but the database call will still return all users in database with empty attendance field.
I need to return only User.school_id that match admin's $session_school_id

tried this
$this->User->Behaviors->attach('Containable');
$from =  $this->data['User']['start_date']['year'] . "-" . $this->data['User']['start_date']['month'] . "-" . $this->data['User']['start_date']['day'];
 $to =  $this->data['User']['end_date']['year'] . "-" . $this->data['User']['end_date']['month'] . "-" . $this->data['User']['end_date']['day'];
$cond = array('Attendance.created BETWEEN ? AND ?' => array($from, $to), 'Attendance.school_id' => $session_school_id);
// return only school user
$cond2 = array('User.school_id' => $session_school_id);
$users = $this->User->find('all', array('contain' => array('Attendance' => array('conditions' => $cond), 'Usermembership', 'User' => array('conditions' => $cond2) )));

this gives me Warning (512): Model "User" is not associated with model "User"

and tried this

$users = $this->User->find('all', array('conditions' => $cond2), array('contain' => array('Attendance' => array('conditions' => $cond), 'Usermembership' )));

does not work either.

cake 1.3
Thank you
Robert

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+u...@googlegroups.com.
To post to this group, send email to cake...@googlegroups.com.

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+u...@googlegroups.com.
To post to this group, send email to cake...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.