Re: Model associations

2012-08-10 Thread André Luis
cricket, thanks for the answear, but it´s not exactly this... I have a menu 
wich is generated dinamically in ALL pages of the site, so it´s a part of 
the layout and the categories information needs to be in all pages.

Em sexta-feira, 10 de agosto de 2012 00h23min04s UTC-3, cricket escreveu:
>
> I'm not sure I follow all of that but I think what you want is a list 
> of all Categories for the main page, and all Products for a given 
> Category. If that's the case, I would set the main page as 
> CategoryController::index(). This is from one of my projects: 
>
> Router::connect( 
> '/catalog', 
> array( 
> 'controller' => Categories', 
> 'action' => 'index' 
> ) 
> ); 
> Router::connect( 
> '/catalog/:slug', 
> array( 
> 'controller' => Categories', 
> 'action' => 'view' 
> ), 
> array( 
> 'slug' => '[-a-z0-9]+', 
> 'pass' => array('slug') 
> ) 
> ); 
>
> Next, fetch the Category list directly from that model: 
>
> public function index() 
> { 
> $this->set( 
> 'data', 
> $this->Category->find( 
> 'all', 
> array( 
> 'order' => array( 
> 'Category.name' => 'ASC' 
> ), 
> 'recursive' => -1 
> ) 
> ) 
> ); 
> } 
>
> public function view($slug = null) 
> { 
> if (empty($slug)) 
> { 
> ... 
> } 
>  
> $this->set( 
> 'data' 
> $this->Category->fetch($slug) 
> ); 
> } 
>
>
> Category model: 
>
> public function fetch($slug) 
> { 
> return $this->find( 
> 'first', 
> array( 
> 'conditions' => array( 
> $this->alias.'.slug' => $slug 
> ), 
> 'contain' => array( 
> 'Product' 
> ) 
> ) 
> ); 
> } 
>
>
> On Thu, Aug 9, 2012 at 10:43 AM, André Luis > 
> wrote: 
> > Hi people, it´s me again! 
> > 
> > I am using a habtm relationship in my application, it works 100% fine... 
> But 
> > the Product menu is created dinamically with it´s Categories... so i 
> have 
> > Product model and the Category model with habtm relationship between 
> them. 
> > 
> > In AppController i have to set at beforeFilter the variable 
> > "products_categories", as i dont need the products of each category 
> right 
> > now i use 
> > 
> $this->set('products_categories",$this->Product->CatProduct->find('all')); 
> > and it works fine... BUT, latter when i need to read the product 
> category 
> > with it´s products, i would use $this->CatProduct->read('*',$id); right? 
> BUT 
> > it´s returning ONLY the category, not the products relateds, but if i 
> > comment the line $this->Product->CatProduct->find('all') it works fine, 
> and 
> > returns me the category and all related products. 
> > 
> > What i am doing wrong? Isnt there anyway to get only the categories them 
> get 
> > one category with it´s relateds? 
> > 
> > Thanks! 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> Groups 
> > "CakePHP" group. 
> > To post to this group, send email to cake...@googlegroups.com. 
>
> > To unsubscribe from this group, send email to 
> > cake-php+u...@googlegroups.com . 
> > Visit this group at http://groups.google.com/group/cake-php?hl=en-US. 
> > 
> > 
>

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




Re: Model associations

2012-08-10 Thread André Luis
Yes i do... I resolved the problem using requestAction, but i know that´s 
not correct.

Em quinta-feira, 9 de agosto de 2012 17h28min29s UTC-3, Mark Wratten 
escreveu:
>
> Do you have var $belongsTo = array('Category', 'Product'); in your 
> CatProduct model?
>
> On Thursday, August 9, 2012 10:43:43 AM UTC-4, André Luis wrote:
>>
>> Hi people, it´s me again!
>>
>> I am using a habtm relationship in my application, it works 100% fine... 
>> But the Product menu is created dinamically with it´s Categories... so i 
>> have Product model and the Category model with habtm relationship between 
>> them.
>>
>> In AppController i have to set at beforeFilter the variable 
>> "products_categories", as i dont need the products of each category right 
>> now i use 
>> $this->set('products_categories",$this->Product->CatProduct->find('all')); 
>> and it works fine... BUT, latter when i need to read the product category 
>> with it´s products, i would use $this->CatProduct->read('*',$id); right? 
>> BUT it´s returning ONLY the category, not the products relateds, but if i 
>> comment the line $this->Product->CatProduct->find('all') it works fine, and 
>> returns me the category and all related products.
>>
>> What i am doing wrong? Isnt there anyway to get only the categories them 
>> get one category with it´s relateds?
>>
>> Thanks!
>>
>

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




Re: Model associations

2012-08-09 Thread lowpass
I'm not sure I follow all of that but I think what you want is a list
of all Categories for the main page, and all Products for a given
Category. If that's the case, I would set the main page as
CategoryController::index(). This is from one of my projects:

Router::connect(
'/catalog',
array(
'controller' => Categories',
'action' => 'index'
)
);
Router::connect(
'/catalog/:slug',
array(
'controller' => Categories',
'action' => 'view'
),
array(
'slug' => '[-a-z0-9]+',
'pass' => array('slug')
)
);

Next, fetch the Category list directly from that model:

public function index()
{
$this->set(
'data',
$this->Category->find(
'all',
array(
'order' => array(
'Category.name' => 'ASC'
),
'recursive' => -1
)
)
);
}

public function view($slug = null)
{
if (empty($slug))
{
...
}

$this->set(
'data'
$this->Category->fetch($slug)
);
}


Category model:

public function fetch($slug)
{
return $this->find(
'first',
array(
'conditions' => array(
$this->alias.'.slug' => $slug
),
'contain' => array(
'Product'
)
)
);
}


On Thu, Aug 9, 2012 at 10:43 AM, André Luis  wrote:
> Hi people, it´s me again!
>
> I am using a habtm relationship in my application, it works 100% fine... But
> the Product menu is created dinamically with it´s Categories... so i have
> Product model and the Category model with habtm relationship between them.
>
> In AppController i have to set at beforeFilter the variable
> "products_categories", as i dont need the products of each category right
> now i use
> $this->set('products_categories",$this->Product->CatProduct->find('all'));
> and it works fine... BUT, latter when i need to read the product category
> with it´s products, i would use $this->CatProduct->read('*',$id); right? BUT
> it´s returning ONLY the category, not the products relateds, but if i
> comment the line $this->Product->CatProduct->find('all') it works fine, and
> returns me the category and all related products.
>
> What i am doing wrong? Isnt there anyway to get only the categories them get
> one category with it´s relateds?
>
> Thanks!
>
> --
> You received this message because you are subscribed to the Google Groups
> "CakePHP" group.
> To post to this group, send email to cake-php@googlegroups.com.
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com.
> Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
>
>

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




Re: Model associations

2012-08-09 Thread Mark Wratten
Do you have var $belongsTo = array('Category', 'Product'); in your 
CatProduct model?

On Thursday, August 9, 2012 10:43:43 AM UTC-4, André Luis wrote:
>
> Hi people, it´s me again!
>
> I am using a habtm relationship in my application, it works 100% fine... 
> But the Product menu is created dinamically with it´s Categories... so i 
> have Product model and the Category model with habtm relationship between 
> them.
>
> In AppController i have to set at beforeFilter the variable 
> "products_categories", as i dont need the products of each category right 
> now i use 
> $this->set('products_categories",$this->Product->CatProduct->find('all')); 
> and it works fine... BUT, latter when i need to read the product category 
> with it´s products, i would use $this->CatProduct->read('*',$id); right? 
> BUT it´s returning ONLY the category, not the products relateds, but if i 
> comment the line $this->Product->CatProduct->find('all') it works fine, and 
> returns me the category and all related products.
>
> What i am doing wrong? Isnt there anyway to get only the categories them 
> get one category with it´s relateds?
>
> Thanks!
>

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




Re: Model associations

2012-08-09 Thread André Luis
I´ve noticed that if i try do use the CatProduct in AppModel, the Product 
model becomes a AppModel object, and not a Product object anymore
=(

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




Re: Model associations

2012-08-09 Thread André Luis
Now when i try to use the find all in appcontroller it seems to remove my 
behaviors for latter uses, what i am doing wrong??

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




Re: Model Associations Question

2012-06-27 Thread Mark Wratten
In you code you have 'className' => 'Bookings'. Shouldn't that be 
'className' = 'Booking' ?

You should also be able to shorten it to - var $belongsTo = 
array('Booking') as you are using booking_id as your foreign key.

MArk

On Wednesday, June 27, 2012 2:34:25 AM UTC-4, Sanfly wrote:
>
> Sorry, I'll repost this - my database is Bookingdate not Bookingnight
>
> Hi
>
> Im having some trouble with a model association - yes, I have tried the 
> manual!
>
> For each Booking I have, I can have many Bookingnights
>
> *Booking*
> Booking.id
> 
>
> *Bookingdate*
> Bookingdate.id
> Bookingdate.booking_id
>
> In my Booking model, I am able to get all the associated Bookingdates 
> without issue.
>
> var $hasMany = array(
> 'Bookingdate' => array(
> 'className' => 'Bookingdates',
> 'foreignKey'=> 'booking_id',
>  
> )
> 
> );
>
> My problem is when I try and go back the other way.  I have my 
> Bookingdate.id, and want to get the associated booking.
>
> I would think that it should be belongsTo in my Bookingdate model?
>
> var $belongsTo = array(
> 'Booking' => array(
> 'className' => 'Bookings',
> 'foreignKey' => 'booking_id'
> )
>
> ); 
>
> ==> Doesnt Work
>
> Is there something obvious that I'm missing?
>
> On Wednesday, 27 June 2012 18:26:42 UTC+12, Sanfly wrote:
>>
>> Hi
>>
>> Im having some trouble with a model association - yes, I have tried the 
>> manual!
>>
>> For each Booking I have, I can have many Bookingnights
>>
>> *Booking*
>> Booking.id
>> 
>>
>> *Bookingnight*
>> Bookingnight.id
>> Bookingnight.booking_id
>>
>> In my Booking model, I am able to get all the associated Bookingnights 
>> without issue.
>>
>> var $hasMany = array(
>> 'Bookingdate' => array(
>> 'className' => 'Bookingdates',
>> 'foreignKey'=> 'booking_id',
>>  
>> )
>> 
>> );
>>
>> My problem is when I try and go back the other way.  I have my 
>> Bookingnight.id, and want to get the associated booking.
>>
>> I would think that it should be belongsTo?
>>
>> var $belongsTo = array(
>> 'Booking' => array(
>> 'className' => 'Bookings',
>> 'foreignKey' => 'booking_id'
>> )
>>
>> ); 
>>
>> ==> Doesnt Work
>>
>> Is there something obvious that I'm missing?
>>
>> Thanks!
>>
>>
>>
>>

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Model Associations Question

2012-06-27 Thread lowpass
This seems more like an HABTM association. A Booking can have/belong
to many BookingDate and vice versa.

I wonder, though, if it might be better to drop the BookingDate model
and instead use date ranges. Something like date_from & date_to, or
arrival & departure, in the bookings table.

On Wed, Jun 27, 2012 at 2:34 AM, Sanfly  wrote:
> Sorry, I'll repost this - my database is Bookingdate not Bookingnight
>
>
> Hi
>
> Im having some trouble with a model association - yes, I have tried the
> manual!
>
> For each Booking I have, I can have many Bookingnights
>
> Booking
> Booking.id
> 
>
> Bookingdate
> Bookingdate.id
> Bookingdate.booking_id
>
> In my Booking model, I am able to get all the associated Bookingdates
> without issue.
>
>
> var $hasMany = array(
>         'Bookingdate' => array(
>         'className' => 'Bookingdates',
>         'foreignKey'    => 'booking_id',
>
>         )
>
>     );
>
> My problem is when I try and go back the other way.  I have my
> Bookingdate.id, and want to get the associated booking.
>
> I would think that it should be belongsTo in my Bookingdate model?
>
>
> var $belongsTo = array(
>         'Booking' => array(
>             'className' => 'Bookings',
>             'foreignKey' => 'booking_id'
>         )
>
>     );
>
> ==> Doesnt Work
>
> Is there something obvious that I'm missing?
>
> On Wednesday, 27 June 2012 18:26:42 UTC+12, Sanfly wrote:
>>
>> Hi
>>
>> Im having some trouble with a model association - yes, I have tried the
>> manual!
>>
>> For each Booking I have, I can have many Bookingnights
>>
>> Booking
>> Booking.id
>> 
>>
>> Bookingnight
>> Bookingnight.id
>> Bookingnight.booking_id
>>
>> In my Booking model, I am able to get all the associated Bookingnights
>> without issue.
>>
>> var $hasMany = array(
>>         'Bookingdate' => array(
>>         'className' => 'Bookingdates',
>>         'foreignKey'    => 'booking_id',
>>
>>         )
>>
>>     );
>>
>> My problem is when I try and go back the other way.  I have my
>> Bookingnight.id, and want to get the associated booking.
>>
>> I would think that it should be belongsTo?
>>
>> var $belongsTo = array(
>>         'Booking' => array(
>>             'className' => 'Bookings',
>>             'foreignKey' => 'booking_id'
>>         )
>>
>>     );
>>
>> ==> Doesnt Work
>>
>> Is there something obvious that I'm missing?
>>
>> Thanks!
>>
>>
>>
> --
> Our newest site for the community: CakePHP Video Tutorials
> http://tv.cakephp.org
> Check out the new CakePHP Questions site http://ask.cakephp.org and help
> others with their CakePHP related questions.
>
>
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group at
> http://groups.google.com/group/cake-php

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Model Associations Question

2012-06-26 Thread Sanfly
Sorry, I'll repost this - my database is Bookingdate not Bookingnight

Hi

Im having some trouble with a model association - yes, I have tried the 
manual!

For each Booking I have, I can have many Bookingnights

*Booking*
Booking.id


*Bookingdate*
Bookingdate.id
Bookingdate.booking_id

In my Booking model, I am able to get all the associated Bookingdates 
without issue.

var $hasMany = array(
'Bookingdate' => array(
'className' => 'Bookingdates',
'foreignKey'=> 'booking_id',
 
)

);

My problem is when I try and go back the other way.  I have my 
Bookingdate.id, and want to get the associated booking.

I would think that it should be belongsTo in my Bookingdate model?

var $belongsTo = array(
'Booking' => array(
'className' => 'Bookings',
'foreignKey' => 'booking_id'
)

); 

==> Doesnt Work

Is there something obvious that I'm missing?

On Wednesday, 27 June 2012 18:26:42 UTC+12, Sanfly wrote:
>
> Hi
>
> Im having some trouble with a model association - yes, I have tried the 
> manual!
>
> For each Booking I have, I can have many Bookingnights
>
> *Booking*
> Booking.id
> 
>
> *Bookingnight*
> Bookingnight.id
> Bookingnight.booking_id
>
> In my Booking model, I am able to get all the associated Bookingnights 
> without issue.
>
> var $hasMany = array(
> 'Bookingdate' => array(
> 'className' => 'Bookingdates',
> 'foreignKey'=> 'booking_id',
>  
> )
> 
> );
>
> My problem is when I try and go back the other way.  I have my 
> Bookingnight.id, and want to get the associated booking.
>
> I would think that it should be belongsTo?
>
> var $belongsTo = array(
> 'Booking' => array(
> 'className' => 'Bookings',
> 'foreignKey' => 'booking_id'
> )
>
> ); 
>
> ==> Doesnt Work
>
> Is there something obvious that I'm missing?
>
> Thanks!
>
>
>
>

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Model Associations

2012-05-25 Thread Mike Griffin
On Thu, May 24, 2012 at 7:37 PM, hill180  wrote:
> Solved:  But I don't know why.  This but this code puts the data where I
> want it, and without the index error:
>

Good to hear, glad I could help.

Mike

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Model Associations

2012-05-24 Thread hill180
Solved:  But I don't know why.  This but this code puts the data where I
want it, and without the index error:


'Contact' => array(
 'className'=>'CONTACT',
 'foreignKey' => false,
 'finderQuery' => 'SELECT Account.AccountID as Contact__ACCOUNT_ID,
contact.contact_full_name as Contact__CONTACT_FULL_NAME FROM CONTACTS AS
contact LEFT
 JOIN Accounts AS Account ON contact.account_id=Account.account WHERE
 Account.AccountID = {$__cakeID__$}'
   )
On Thu, May 24, 2012 at 9:38 AM, hill180  wrote:

> Ok.
> Sorry for the last email.
>
> it made no sense:
>
> What I was trying to say is that I am getting
> *Notice* (8): Undefined index: Contacts
>
> I copied the SQL Dumb (from the finderquery) in MSSQL Manager and it works.
>
> Just doing a debug($results) which is the results of the find query.
>
> Also it gets me 3 undefined Index errors, which matches the records for
> this account.
>
> Thank you.
>
>
> On Thu, May 24, 2012 at 10:33 AM, hill180  wrote:
>
>> Thank you so much.  I think I am 99% there.
>>
>> Get the following error three times, (that is actually how many contacts
>> are in the DB for the customer I was looking up.
>>
>> debug($results);
>>
>> *Notice* (8): Undefined index: Contacts [*
>> CORE\Cake\Model\Datasource\DboSource.php*, line *1412*]
>> Code Context
>>
>> }} else {
>> $this->_mergeAssociation($row, $fetch, $association, $type, $selfJoin);
>>
>> $data = array(
>>  'TblAccount' => array(
>>  ),
>>  'Address' => array(
>>  ),
>>  'Contacts' => array(
>>  )
>> )
>> $merge = array(
>>  (int) 0 => array(
>>  ),
>>  (int) 1 => array(
>>  ),
>>  (int) 2 => array(
>>  )
>> )
>> $association = 'Contacts'
>> $type = 'hasMany'
>> $selfJoin = false
>> $i = (int) 1
>> $row = array(
>>  (int) 0 => array(
>>  )
>> )
>> $insert = array()
>>
>> DboSource::_mergeAssociation() - CORE\Cake\Model\Datasource\DboSource.php, 
>> line 1412
>> DboSource::queryAssociation() - CORE\Cake\Model\Datasource\DboSource.php, 
>> line 1274
>> DboSource::read() - CORE\Cake\Model\Datasource\DboSource.php, line 1087
>> Sqlserver::read() - CORE\Cake\Model\Datasource\Database\Sqlserver.php, line 
>> 600
>> Model::find() - CORE\Cake\Model\Model.php, line 2698
>> TblAccountsController::view() - APP\Controller\TblAccountsController.php, 
>> line 28
>> ReflectionMethod::invokeArgs() - [internal], line ??
>> Controller::invokeAction() - CORE\Cake\Controller\Controller.php, line 485
>> Dispatcher::_invoke() - CORE\Cake\Routing\Dispatcher.php, line 103
>> Dispatcher::dispatch() - CORE\Cake\Routing\Dispatcher.php, line 85
>> [main] - APP\webroot\index.php, line 92
>>
>>
>>
>>
>>
>>
>>
>> Co
>>
>> I copied the SQL Dumb into MS SQL query and it gave me the records I
>> needed.
>>
>> Thanks!
>>
>>
>> On Thu, May 24, 2012 at 9:38 AM, Mike Griffin  wrote:
>>
>>> On Thu, May 24, 2012 at 3:14 PM, hill180  wrote:
>>> > Yes.
>>> >
>>> > As a disclaimer, I didn't write the original schema.
>>> >
>>> > Account_ID is for the systems account number (primary key)
>>> > Account is for the logical account number (used by the company)
>>> >
>>> > The Account Address table use the Account_ID as the foreign key, but
>>> the
>>> > Contact Table uses the Account Number as the foreign key.
>>> >
>>> > SQLDUMP:
>>> >
>>> > SELECT [CONTACT_FULL_NAME] AS [Contact__CONTACT_FULL_NAME],
>>> > [Contact].[CONTACT_FIRST_NAME] AS [Contact__CONTACT_FIRST_NAME] FROM
>>> > [CONTACTS] AS [Contact] WHERE [Contact].[Account_ID] =
>>> [Accounts].[Account]
>>> >
>>> >
>>> > error:
>>> >
>>> > Error: SQLSTATE[42000]: [Microsoft][SQL Server Native Client
>>> > 11.0][SQL Server]The multi-part identifier "Accounts.Account" could
>>> not be
>>> > bound.
>>> >
>>>
>>> Right so.
>>>
>>> You can do it this way instead. Remove the conditions array from the
>>> model association and put this in:
>>> 'finderQuery' => 'SELECT Contact.name FROM contacts AS Contact LEFT
>>> JOIN accounts AS Account ON Contact.account_id=Account.account WHERE
>>> Account.AccountID = {$__cakeID__$}'
>>>
>>> You can edit the SELECT query to return whatever values you want but
>>> leave in the {$__cakeID__$} bit as it is the value of the primary key.
>>>
>>> I hope this makes sense.
>>>
>>> Mike.
>>>
>>> --
>>> Our newest site for the community: CakePHP Video Tutorials
>>> http://tv.cakephp.org
>>> Check out the new CakePHP Questions site http://ask.cakephp.org and
>>> help others with their CakePHP related questions.
>>>
>>>
>>> To unsubscribe from this group, send email to
>>> cake-php+unsubscr...@googlegroups.com For more options, visit this
>>> group at http://groups.google.com/group/cake-php
>>>
>>
>>
>

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+u

Re: Model Associations

2012-05-24 Thread hill180
Ok.
Sorry for the last email.

it made no sense:

What I was trying to say is that I am getting
*Notice* (8) : Undefined index: Contacts

I copied the SQL Dumb (from the finderquery) in MSSQL Manager and it works.

Just doing a debug($results) which is the results of the find query.

Also it gets me 3 undefined Index errors, which matches the records for
this account.

Thank you.


On Thu, May 24, 2012 at 10:33 AM, hill180  wrote:

> Thank you so much.  I think I am 99% there.
>
> Get the following error three times, (that is actually how many contacts
> are in the DB for the customer I was looking up.
>
> debug($results);
>
> *Notice* (8): Undefined index: Contacts [*
> CORE\Cake\Model\Datasource\DboSource.php*, line *1412*]
> Code Context
>
> }} else {
> $this->_mergeAssociation($row, $fetch, $association, $type, $selfJoin);
>
> $data = array(
>   'TblAccount' => array(
>   ),
>   'Address' => array(
>   ),
>   'Contacts' => array(
>   )
> )
> $merge = array(
>   (int) 0 => array(
>   ),
>   (int) 1 => array(
>   ),
>   (int) 2 => array(
>   )
> )
> $association = 'Contacts'
> $type = 'hasMany'
> $selfJoin = false
> $i = (int) 1
> $row = array(
>   (int) 0 => array(
>   )
> )
> $insert = array()
>
> DboSource::_mergeAssociation() - CORE\Cake\Model\Datasource\DboSource.php, 
> line 1412
> DboSource::queryAssociation() - CORE\Cake\Model\Datasource\DboSource.php, 
> line 1274
> DboSource::read() - CORE\Cake\Model\Datasource\DboSource.php, line 1087
> Sqlserver::read() - CORE\Cake\Model\Datasource\Database\Sqlserver.php, line 
> 600
> Model::find() - CORE\Cake\Model\Model.php, line 2698
> TblAccountsController::view() - APP\Controller\TblAccountsController.php, 
> line 28
> ReflectionMethod::invokeArgs() - [internal], line ??
> Controller::invokeAction() - CORE\Cake\Controller\Controller.php, line 485
> Dispatcher::_invoke() - CORE\Cake\Routing\Dispatcher.php, line 103
> Dispatcher::dispatch() - CORE\Cake\Routing\Dispatcher.php, line 85
> [main] - APP\webroot\index.php, line 92
>
>
>
>
>
>
>
> Co
>
> I copied the SQL Dumb into MS SQL query and it gave me the records I
> needed.
>
> Thanks!
>
>
> On Thu, May 24, 2012 at 9:38 AM, Mike Griffin  wrote:
>
>> On Thu, May 24, 2012 at 3:14 PM, hill180  wrote:
>> > Yes.
>> >
>> > As a disclaimer, I didn't write the original schema.
>> >
>> > Account_ID is for the systems account number (primary key)
>> > Account is for the logical account number (used by the company)
>> >
>> > The Account Address table use the Account_ID as the foreign key, but the
>> > Contact Table uses the Account Number as the foreign key.
>> >
>> > SQLDUMP:
>> >
>> > SELECT [CONTACT_FULL_NAME] AS [Contact__CONTACT_FULL_NAME],
>> > [Contact].[CONTACT_FIRST_NAME] AS [Contact__CONTACT_FIRST_NAME] FROM
>> > [CONTACTS] AS [Contact] WHERE [Contact].[Account_ID] =
>> [Accounts].[Account]
>> >
>> >
>> > error:
>> >
>> > Error: SQLSTATE[42000]: [Microsoft][SQL Server Native Client
>> > 11.0][SQL Server]The multi-part identifier "Accounts.Account" could not
>> be
>> > bound.
>> >
>>
>> Right so.
>>
>> You can do it this way instead. Remove the conditions array from the
>> model association and put this in:
>> 'finderQuery' => 'SELECT Contact.name FROM contacts AS Contact LEFT
>> JOIN accounts AS Account ON Contact.account_id=Account.account WHERE
>> Account.AccountID = {$__cakeID__$}'
>>
>> You can edit the SELECT query to return whatever values you want but
>> leave in the {$__cakeID__$} bit as it is the value of the primary key.
>>
>> I hope this makes sense.
>>
>> Mike.
>>
>> --
>> Our newest site for the community: CakePHP Video Tutorials
>> http://tv.cakephp.org
>> Check out the new CakePHP Questions site http://ask.cakephp.org and help
>> others with their CakePHP related questions.
>>
>>
>> To unsubscribe from this group, send email to
>> cake-php+unsubscr...@googlegroups.com For more options, visit this group
>> at http://groups.google.com/group/cake-php
>>
>
>

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Model Associations

2012-05-24 Thread hill180
Thank you so much.  I think I am 99% there.

Get the following error three times, (that is actually how many contacts
are in the DB for the customer I was looking up.

debug($results);

*Notice* (8) : Undefined index: Contacts [*
CORE\Cake\Model\Datasource\DboSource.php*, line *1412*]
Code  Context 

}} else {
  $this->_mergeAssociation($row, $fetch, $association, $type,
$selfJoin);

$data = array(
'TblAccount' => array(
),
'Address' => array(
),
'Contacts' => array(
)
)
$merge = array(
(int) 0 => array(
),
(int) 1 => array(
),
(int) 2 => array(
)
)
$association = 'Contacts'
$type = 'hasMany'
$selfJoin = false
$i = (int) 1
$row = array(
(int) 0 => array(
)
)
$insert = array()

DboSource::_mergeAssociation() -
CORE\Cake\Model\Datasource\DboSource.php, line 1412
DboSource::queryAssociation() -
CORE\Cake\Model\Datasource\DboSource.php, line 1274
DboSource::read() - CORE\Cake\Model\Datasource\DboSource.php, line 1087
Sqlserver::read() - CORE\Cake\Model\Datasource\Database\Sqlserver.php, line 600
Model::find() - CORE\Cake\Model\Model.php, line 2698
TblAccountsController::view() -
APP\Controller\TblAccountsController.php, line 28
ReflectionMethod::invokeArgs() - [internal], line ??
Controller::invokeAction() - CORE\Cake\Controller\Controller.php, line 485
Dispatcher::_invoke() - CORE\Cake\Routing\Dispatcher.php, line 103
Dispatcher::dispatch() - CORE\Cake\Routing\Dispatcher.php, line 85
[main] - APP\webroot\index.php, line 92







Co

I copied the SQL Dumb into MS SQL query and it gave me the records I needed.

Thanks!


On Thu, May 24, 2012 at 9:38 AM, Mike Griffin  wrote:

> On Thu, May 24, 2012 at 3:14 PM, hill180  wrote:
> > Yes.
> >
> > As a disclaimer, I didn't write the original schema.
> >
> > Account_ID is for the systems account number (primary key)
> > Account is for the logical account number (used by the company)
> >
> > The Account Address table use the Account_ID as the foreign key, but the
> > Contact Table uses the Account Number as the foreign key.
> >
> > SQLDUMP:
> >
> > SELECT [CONTACT_FULL_NAME] AS [Contact__CONTACT_FULL_NAME],
> > [Contact].[CONTACT_FIRST_NAME] AS [Contact__CONTACT_FIRST_NAME] FROM
> > [CONTACTS] AS [Contact] WHERE [Contact].[Account_ID] =
> [Accounts].[Account]
> >
> >
> > error:
> >
> > Error: SQLSTATE[42000]: [Microsoft][SQL Server Native Client
> > 11.0][SQL Server]The multi-part identifier "Accounts.Account" could not
> be
> > bound.
> >
>
> Right so.
>
> You can do it this way instead. Remove the conditions array from the
> model association and put this in:
> 'finderQuery' => 'SELECT Contact.name FROM contacts AS Contact LEFT
> JOIN accounts AS Account ON Contact.account_id=Account.account WHERE
> Account.AccountID = {$__cakeID__$}'
>
> You can edit the SELECT query to return whatever values you want but
> leave in the {$__cakeID__$} bit as it is the value of the primary key.
>
> I hope this makes sense.
>
> Mike.
>
> --
> Our newest site for the community: CakePHP Video Tutorials
> http://tv.cakephp.org
> Check out the new CakePHP Questions site http://ask.cakephp.org and help
> others with their CakePHP related questions.
>
>
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group
> at http://groups.google.com/group/cake-php
>

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Model Associations

2012-05-24 Thread Mike Griffin
On Thu, May 24, 2012 at 3:14 PM, hill180  wrote:
> Yes.
>
> As a disclaimer, I didn't write the original schema.
>
> Account_ID is for the systems account number (primary key)
> Account is for the logical account number (used by the company)
>
> The Account Address table use the Account_ID as the foreign key, but the
> Contact Table uses the Account Number as the foreign key.
>
> SQLDUMP:
>
> SELECT [CONTACT_FULL_NAME] AS [Contact__CONTACT_FULL_NAME],
> [Contact].[CONTACT_FIRST_NAME] AS [Contact__CONTACT_FIRST_NAME] FROM
> [CONTACTS] AS [Contact] WHERE [Contact].[Account_ID] = [Accounts].[Account]
>
>
> error:
>
> Error: SQLSTATE[42000]: [Microsoft][SQL Server Native Client
> 11.0][SQL Server]The multi-part identifier "Accounts.Account" could not be
> bound.
>

Right so.

You can do it this way instead. Remove the conditions array from the
model association and put this in:
'finderQuery' => 'SELECT Contact.name FROM contacts AS Contact LEFT
JOIN accounts AS Account ON Contact.account_id=Account.account WHERE
Account.AccountID = {$__cakeID__$}'

You can edit the SELECT query to return whatever values you want but
leave in the {$__cakeID__$} bit as it is the value of the primary key.

I hope this makes sense.

Mike.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Model Associations

2012-05-24 Thread hill180
Yes.

As a disclaimer, I didn't write the original schema.

Account_ID is for the systems account number (primary key)
Account is for the logical account number (used by the company)

The Account Address table use the Account_ID as the foreign key, but the
Contact Table uses the Account Number as the foreign key.

SQLDUMP:

SELECT [CONTACT_FULL_NAME] AS [Contact__CONTACT_FULL_NAME],
[Contact].[CONTACT_FIRST_NAME] AS [Contact__CONTACT_FIRST_NAME] FROM
[CONTACTS] AS [Contact] WHERE [Contact].[Account_ID] = [Accounts].[Account]

error:

Error: SQLSTATE[42000]: [Microsoft][SQL Server Native Client
11.0][SQL Server]The multi-part identifier "Accounts.Account" could not be
bound.


On Thu, May 24, 2012 at 3:28 AM, Mike Griffin  wrote:

> On Thu, May 24, 2012 at 1:50 AM, hill180  wrote:
> > AccountID = AccountID on the Account and the Address for the Account, no
> > problems here.
> >
> >
> > The problem is the contacts.
> >
> > The join is Contact.Account_id = Accounts.Account (not Account_ID)
> >
> > Error: SQLSTATE[42000]: [Microsoft][SQL Server Native Client 11.0][SQL
> > Server]The multi-part identifier "Accounts.Account" could not be bound.
> >
>
> Are you saying that the Accounts.Account and Accounts.AccountID are
> different fields and have different values?
>
> What's the actual SQL statement that is being created and causes the error?
>
> Mike.
>
> --
> Our newest site for the community: CakePHP Video Tutorials
> http://tv.cakephp.org
> Check out the new CakePHP Questions site http://ask.cakephp.org and help
> others with their CakePHP related questions.
>
>
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group
> at http://groups.google.com/group/cake-php
>

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Model Associations

2012-05-24 Thread Mike Griffin
On Thu, May 24, 2012 at 1:50 AM, hill180  wrote:
> AccountID = AccountID on the Account and the Address for the Account, no
> problems here.
>
>
> The problem is the contacts.
>
> The join is Contact.Account_id = Accounts.Account (not Account_ID)
>
> Error: SQLSTATE[42000]: [Microsoft][SQL Server Native Client 11.0][SQL
> Server]The multi-part identifier "Accounts.Account" could not be bound.
>

Are you saying that the Accounts.Account and Accounts.AccountID are
different fields and have different values?

What's the actual SQL statement that is being created and causes the error?

Mike.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Model Associations and Inserting through Associations

2012-05-05 Thread stork
If user is not logged in, then in Event form:

echo $this->Form->input('Event.user_id', array('type' => 'hidden', 'value' 
=> $user['User']['id']));

and in controller:

$this->Event->create($this->request->data);
if ($this->Event->save()) {
...

Do not forget to use SecurityComponent in AppController, so nobody can 
change value of that hidden field in browser.

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Model Associations and Inserting through Associations

2012-05-05 Thread Nate
I should have specified - the user doesn't necessarily have to be the 
logged in user. It could be any user, in which case $this->Auth->user('id') 
doesn't fit my needs. This is closer, I just need to figure out how to grab 
the user id from the users/view page.

On Saturday, May 5, 2012 10:33:09 AM UTC-6, stork wrote:
>
> $this->Event->create($this->request->data);
> $this->Event->set('user_id', $this->Auth->user('id'));
> if ($this->Event->save()) {
> ...
>

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Model Associations and Inserting through Associations

2012-05-05 Thread Nate
Trying to learn it through straight code before I dive into any console 
commands. One of the biggest reasons that I've put off using MVC is because 
I like to feel like I'm in control. Yes, probably dumb, but it makes more 
sense to my fragile brain.

On Saturday, May 5, 2012 7:57:13 AM UTC-6, Michael wrote:
>
> You should take some time to learn how to use bake. It will setup the 
> basics for you based on your database and will serve as a great 
> example of how to do things. 
>
>
> http://book.cakephp.org/2.0/en/console-and-shells/code-generation-with-bake.html
>  
>
> There are many tutorials out there about setting it up. 
>
> ~Michael 
>

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Model Associations and Inserting through Associations

2012-05-05 Thread stork
$this->Event->create($this->request->data);
$this->Event->set('user_id', $this->Auth->user('id'));
if ($this->Event->save()) {
...

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Model Associations and Inserting through Associations

2012-05-05 Thread Michael Gaiser
You should take some time to learn how to use bake. It will setup the
basics for you based on your database and will serve as a great
example of how to do things.

http://book.cakephp.org/2.0/en/console-and-shells/code-generation-with-bake.html

There are many tutorials out there about setting it up.

~Michael

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Model associations and combobox.

2011-04-16 Thread cricket
On Sat, Apr 16, 2011 at 2:34 PM, cricket  wrote:
>
> public function add()
> {
>        if (!empty($this->data))
>        {
>                // attempt to save
>        }
>
>        $this->set(
>                'fabricantes',
>                $this->Carro->Fabricante->find('list')
>        );
> }
>
> echo $this->Form->select('Carro.fabricante_id', $fabricantes);
>

One other thing. For find('list') Cake fetches the primary key
(usually id) and the "display field" which defaults to a colmn called
"name". So you'll need to do this in Carro model:

public $displayField = 'nome';

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Model associations and combobox.

2011-04-16 Thread cricket
On Fri, Apr 15, 2011 at 10:45 AM, Uriel Juliatti
 wrote:
> Hey everybody
>
> I'd like to know how to display a list of
> Manufacturers (associated with Cars) in a combobox when I create cars.
>
> My Mysql query returns it:
>
> SELECT `Carro`.`id`, `Carro`.`fabricante_id`, `Carro`.`nome`,
> `Carro`.`modelo`, `Carro`.`blindado`, `Carro`.`cor`, `Carro`.`ano`,
> `Carro`.`preco`, `Fabricante`.`id`, `Fabricante`.`nome` FROM `carros`
> AS `Carro` LEFT JOIN `fabricantes` AS `Fabricante` ON
> (`Carro`.`fabricante_id` = `Fabricante`.`id`) WHERE 1 = 1
>
> // Where fabricante = Manufacturer and Carro = Car.
>
> My models are:
>
> models/carro.php:
>  class Carro extends AppModel
>  {
>       var $name = "Carro";
>       var $belongsTo = 'Fabricante';
> }
>
> models/fabricante.php:
>
>  class Fabricante extends AppModel
>  {
>       var $name = "Fabricante";
>       var $hasMany = array('Carro' => array(
>                   'className'     => 'Carro',
>                               'foreignKey'    => 'fabricante_id',
>                       'dependent'=> true
>                                                        )
>                  );
> }
>
> Does anyone have any idea how to display the Manufacturers into a
> combobox at Cars 'add' view?

public function add()
{
if (!empty($this->data))
{
// attempt to save
}

$this->set(
'fabricantes',
$this->Carro->Fabricante->find('list')
);
}

echo $this->Form->select('Carro.fabricante_id', $fabricantes);

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php


Re: Model associations problem

2010-06-17 Thread Jeremy Burns | Class Outfit
The  results are perfectly correct for the code you are running; you are 
finding all Trackers. Your code:

$this->set('trackers', $this->User->Tracker->find('all'));

... is saying "go to the User model, then leap out to the Tracker model and 
bring me back all Trackers".

To filter the search, pass in a condition:

$this->set(
'trackers',
$this->User->Tracker->find(
'all',
array(
'conditions' = array(
'Tracker.user_id' => $userId
// where $userId is 'this' user
)
)
)
);

Or (in my opinion the better strategy) use the containable behaviour: 
http://book.cakephp.org/view/1323/Containable.

Jeremy Burns
Class Outfit

jeremybu...@classoutfit.com
http://www.classoutfit.com

On 17 Jun 2010, at 00:43, ryanl wrote:

> I'm in the process of creating my first web application with CakePHP,
> however I've run into some problems. I'll just start with the code:
> 
> 
> class User extends AppModel
> {
>   public $name = 'User';
>   public $belongsTo = 'Group';
>   public $hasMany = array(
>   'Tracker' => array(
>   'className' => 'Tracker',
>   'foreignKey' => 'user_id',
>   'dependent' => true,
>   'order' => 'Tracker.created DESC'));
> 
>   public $validate = array(
>   'username' => 'alphaNumeric',
>   'password' => 'notEmpty'
>   );
> }
> 
> 
> class Tracker extends AppModel
> {
>   public $name = 'Tracker';
>   public $belongsTo = 'User';
>   public $hasMany = array(
>   'Log' => array(
>   'className' => 'Log',
>   'foreignKey' => 'tracker_id',
>   'dependent' => true,
>   'order' => 'Log.created DESC'));
> 
>   public $validate = array(
>   'name' => 'alphaNumeric',
>   );
> }
> 
> 
> class Log extends AppModel
> {
>   public $name = 'Log';
>   public $belongsTo = 'Tracker';
>   public $validate = array();
> }
> 
> 
> Basically you can see that each user has a tracker, and each tracker
> has a log. The problem is that when I'm displaying trackers, I want to
> display for each user ONLY the trackers that he or she owns. But
> instead of doing that, it returns back all the trackers, including
> ones that the user doesn't own. This is the code that I'm using:
> 
> // inside of app/controllers/user_controller.php
> 
> $this->set('trackers', $this->User->Tracker->find('all'));
> $this->set('totalTrackers', $this->User->Tracker->find('count'));
> 
> 
> Can someone help me solve the problem?
> Thanks.
> 
> Check out the new CakePHP Questions site http://cakeqs.org and help others 
> with their CakePHP related questions.
> 
> You received this message because you are subscribed to the Google Groups 
> "CakePHP" group.
> To post to this group, send email to cake-php@googlegroups.com
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
> http://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: Model Associations - just feels wrong

2010-03-19 Thread TheHerk
Thanks for taking a look at that LunarDraco. At first, the database
was going to be configured with no surrogate keys where there was a
logical candidate key. At least for parent tables. Then I found out
that cakephp does not support compound keys, so I had to abandon that
plan. Also, I found out that it is generally better to do as you said
with using separate program-use-only surrogate keys in this type of
application. Apparently there are entire Vi/Emacs style debates of
surrogates vs. logical data representation. At any rate, I have
altered that in almost all cases, and with your recommendation may
alter the rest.

Thank you so much for your information about the zip codes; I actually
had no idea that was the case. I will make the changes you recommend.

I finally posted the full thing for people to see. Here is the full
diagram so far, without the updated zip code set up. Keep in mind
these are just representing the entities not the tables hence the
ClassName instead of table_names.

pdf: http://www.filedropper.com/mcidclassesrev6
dia: http://www.filedropper.com/mcidclassesrev6_1


On Mar 19, 12:21 pm, LunarDraco  wrote:
> The problem I see with your model is in your ZipLocation you have the
> code set to a PK.
>
> The Problem:
> It is often thought that a zipcode belongs to only one city. And that
> a city can have many zipcodes. There are no such rules in the postal
> system.
>
> One zip code could and often overlaps many city boundaries. Especially
> in rural areas.
> So your ZipLocation Table as it is defined could not have records like
> the following without violating the PK:
> 84087, Woods Cross, UT
> 84087, West Bountiful, UT
>
> I see this design quite a bit and this is where you will run into
> trouble. But probably not until you get quite a ways down the path of
> development and start adding a bunch of data.
>
> You should follow the naming scheme for table names and special field
> names like (id, [fkmodel]_id, name, description, created, modified)
> this will help tremendously during the baking of your model as cake
> will pick up all the appropriate hasOne, hasMany, belongsTo, etc. This
> will also help in your building your forms for creating your dropdowns
> and autofill text as if your models have a name field it is used in
> the dropdown. I don't like to see user data stored in the PK. If you
> need it to maintain uniqueness (which you don't want to in this case)
> there are other ways to guarantee the user data is unique. PK and FK
> should be for the data relations, and program use only.
> I would review section 2.4 of the 
> manualhttp://book.cakephp.org/view/22/CakePHP-Conventions
> which talks about all of the file naming, model and database,
> controller and view conventions.
>
> Creating the tables as below allows you to have multiple cities in the
> same zipcode and still maintain proper relations between the tables.
> Your Model relations still remain as Location hasOne ZipLocation,
> State hasMany ZipLocation, ZipLocations belongTo Locations, and
> ZipLocations belongTo States. And your Form can display the proper
> autofill selections when the user enters 84087 or any other zips that
> might have multiple cities.
>
> --
> locations
> --
> id (PK)
> name
> street1
> street 2
> zip_location_id (FK)
> ...
>
> --
> zip_locations
> --
> id (PK)
> zipcode (indexed)
> city
> state_id (FK)
>
> --
> states
> --
> id (PK)
> code
> name

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: Model Associations - just feels wrong

2010-03-19 Thread LunarDraco
The problem I see with your model is in your ZipLocation you have the
code set to a PK.

The Problem:
It is often thought that a zipcode belongs to only one city. And that
a city can have many zipcodes. There are no such rules in the postal
system.

One zip code could and often overlaps many city boundaries. Especially
in rural areas.
So your ZipLocation Table as it is defined could not have records like
the following without violating the PK:
84087, Woods Cross, UT
84087, West Bountiful, UT

I see this design quite a bit and this is where you will run into
trouble. But probably not until you get quite a ways down the path of
development and start adding a bunch of data.

You should follow the naming scheme for table names and special field
names like (id, [fkmodel]_id, name, description, created, modified)
this will help tremendously during the baking of your model as cake
will pick up all the appropriate hasOne, hasMany, belongsTo, etc. This
will also help in your building your forms for creating your dropdowns
and autofill text as if your models have a name field it is used in
the dropdown. I don't like to see user data stored in the PK. If you
need it to maintain uniqueness (which you don't want to in this case)
there are other ways to guarantee the user data is unique. PK and FK
should be for the data relations, and program use only.
I would review section 2.4 of the manual 
http://book.cakephp.org/view/22/CakePHP-Conventions
which talks about all of the file naming, model and database,
controller and view conventions.

Creating the tables as below allows you to have multiple cities in the
same zipcode and still maintain proper relations between the tables.
Your Model relations still remain as Location hasOne ZipLocation,
State hasMany ZipLocation, ZipLocations belongTo Locations, and
ZipLocations belongTo States. And your Form can display the proper
autofill selections when the user enters 84087 or any other zips that
might have multiple cities.

--
locations
--
id (PK)
name
street1
street 2
zip_location_id (FK)
...

--
zip_locations
--
id (PK)
zipcode (indexed)
city
state_id (FK)

--
states
--
id (PK)
code
name

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: Model Associations - just feels wrong

2010-03-19 Thread TheHerk
Antonio. I cannot post that; I have not built them yet. Before I build
the models I wanted to make sure I had this class diagram whooped. It
sounds like I correctly understood it, so I'm going to get the models
built soon. When that happens I will post them here. In the mean time,
if you'd like to see the entire diagram including the cake
relationships, send me an email. I'd be happy to reply with the file.
Thanks again for the assistance.

On Mar 19, 6:13 am, Antônio Marco  wrote:
> Hi, TheKerk, morning!
>
> Can you post the models association's code here?
>
> Thanks.
>
> On 17 mar, 23:41, TheHerk  wrote:
>
>
>
> > Here is a link to a screenshot of a class diagram I am working on,
> > with noted model associations. There are several relationships in the
> > diagram that feel wrong to me. The one in the diagram that illustrates
> > this is between ZipLocation and State. In this case, state is
> > enumerated in its own table. For some reason, to me, it seems strange
> > that  ZipLocation, the parent, is belongsTo. I keep thinking in my
> > head, “Each ZipLocation has one associated State,” but it doesn't seem
> > to work that way. There are several more instances of this dilemma,
> > but they are just the same.
>
> >http://i8.photobucket.com/albums/a24/atomickeg/public/classes.png
>
> > Does this look remotely correct?

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: Model Associations - just feels wrong

2010-03-19 Thread Antônio Marco
Hi, TheKerk, morning!

Can you post the models association's code here?

Thanks.

On 17 mar, 23:41, TheHerk  wrote:
> Here is a link to a screenshot of a class diagram I am working on,
> with noted model associations. There are several relationships in the
> diagram that feel wrong to me. The one in the diagram that illustrates
> this is between ZipLocation and State. In this case, state is
> enumerated in its own table. For some reason, to me, it seems strange
> that  ZipLocation, the parent, is belongsTo. I keep thinking in my
> head, “Each ZipLocation has one associated State,” but it doesn't seem
> to work that way. There are several more instances of this dilemma,
> but they are just the same.
>
> http://i8.photobucket.com/albums/a24/atomickeg/public/classes.png
>
> Does this look remotely correct?

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: Model Associations - just feels wrong

2010-03-18 Thread Miles J
This is how I see it:

If your table has a column that is an ID to another table, this table
is the child and the foreign table is the parent. So hence, child
belongs to parent.

And reversed its, parent has many child (or has one).

On Mar 18, 7:02 pm, TheHerk  wrote:
> Phew. I was really hoping I would here this confirmation you two are
> providing. I was on the fence and worried I'd come to understand it
> wrong. Maybe serendipity, but I feel like I'm in good shape now.
> Thanks a lot.
>
> On Mar 18, 7:14 pm, Miles J  wrote:
>
> > The terms "hasOne", "hasMany", "belongsTo" and "HABTM" and just terms
> > to make it easier to understand. It doesn't actually mean that one
> > table belongs to another table 100% of the time, its just the easy way
> > of saying.
>
> > But in your example, it seems like ZipLocation belongsTo State and
> > State hasMany ZipLocation.
>
> > On Mar 18, 12:18 pm, TheHerk  wrote:
>
> > > What you say makes sense. It makes sense to me that zip belong to
> > > states because they really are the further breakdown. What I don't
> > > understand is relations where child classes have many different
> > > parents. I assume I am just over-thinking it, as per usual. Maybe it
> > > really is as simple as it seems. Thank you for your help.
>
> > > If anybody is willing to look at the entire class diagram and tell me
> > > if I'm headed down the wrong path or possible have it correct, please
> > > do so. I'd be happy to email to you.
>
> > > On Mar 18, 9:00 am, John Andersen  wrote:
>
> > > > If I understand you correctly, then you consider the ZipLocation to be
> > > > the parent of the State?
>
> > > > My understanding of the situation is the reverse, one State may have
> > > > one or more ZipLocations, so one ZipLocation belongs to one State.
>
> > > > So your diagram looks correct with regard to the relationship between
> > > > ZipLocation and State :)
> > > > Enjoy,
> > > >    John
>
> > > > On Mar 18, 4:41 am, TheHerk  wrote:
>
> > > > > Here is a link to a screenshot of a class diagram I am working on,
> > > > > with noted model associations. There are several relationships in the
> > > > > diagram that feel wrong to me. The one in the diagram that illustrates
> > > > > this is between ZipLocation and State. In this case, state is
> > > > > enumerated in its own table. For some reason, to me, it seems strange
> > > > > that  ZipLocation, the parent, is belongsTo. I keep thinking in my
> > > > > head, “Each ZipLocation has one associated State,” but it doesn't seem
> > > > > to work that way. There are several more instances of this dilemma,
> > > > > but they are just the same.
>
> > > > >http://i8.photobucket.com/albums/a24/atomickeg/public/classes.png
>
> > > > > Does this look remotely correct?

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: Model Associations - just feels wrong

2010-03-18 Thread TheHerk
Phew. I was really hoping I would here this confirmation you two are
providing. I was on the fence and worried I'd come to understand it
wrong. Maybe serendipity, but I feel like I'm in good shape now.
Thanks a lot.

On Mar 18, 7:14 pm, Miles J  wrote:
> The terms "hasOne", "hasMany", "belongsTo" and "HABTM" and just terms
> to make it easier to understand. It doesn't actually mean that one
> table belongs to another table 100% of the time, its just the easy way
> of saying.
>
> But in your example, it seems like ZipLocation belongsTo State and
> State hasMany ZipLocation.
>
> On Mar 18, 12:18 pm, TheHerk  wrote:
>
>
>
> > What you say makes sense. It makes sense to me that zip belong to
> > states because they really are the further breakdown. What I don't
> > understand is relations where child classes have many different
> > parents. I assume I am just over-thinking it, as per usual. Maybe it
> > really is as simple as it seems. Thank you for your help.
>
> > If anybody is willing to look at the entire class diagram and tell me
> > if I'm headed down the wrong path or possible have it correct, please
> > do so. I'd be happy to email to you.
>
> > On Mar 18, 9:00 am, John Andersen  wrote:
>
> > > If I understand you correctly, then you consider the ZipLocation to be
> > > the parent of the State?
>
> > > My understanding of the situation is the reverse, one State may have
> > > one or more ZipLocations, so one ZipLocation belongs to one State.
>
> > > So your diagram looks correct with regard to the relationship between
> > > ZipLocation and State :)
> > > Enjoy,
> > >    John
>
> > > On Mar 18, 4:41 am, TheHerk  wrote:
>
> > > > Here is a link to a screenshot of a class diagram I am working on,
> > > > with noted model associations. There are several relationships in the
> > > > diagram that feel wrong to me. The one in the diagram that illustrates
> > > > this is between ZipLocation and State. In this case, state is
> > > > enumerated in its own table. For some reason, to me, it seems strange
> > > > that  ZipLocation, the parent, is belongsTo. I keep thinking in my
> > > > head, “Each ZipLocation has one associated State,” but it doesn't seem
> > > > to work that way. There are several more instances of this dilemma,
> > > > but they are just the same.
>
> > > >http://i8.photobucket.com/albums/a24/atomickeg/public/classes.png
>
> > > > Does this look remotely correct?

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: Model Associations - just feels wrong

2010-03-18 Thread Miles J
The terms "hasOne", "hasMany", "belongsTo" and "HABTM" and just terms
to make it easier to understand. It doesn't actually mean that one
table belongs to another table 100% of the time, its just the easy way
of saying.

But in your example, it seems like ZipLocation belongsTo State and
State hasMany ZipLocation.

On Mar 18, 12:18 pm, TheHerk  wrote:
> What you say makes sense. It makes sense to me that zip belong to
> states because they really are the further breakdown. What I don't
> understand is relations where child classes have many different
> parents. I assume I am just over-thinking it, as per usual. Maybe it
> really is as simple as it seems. Thank you for your help.
>
> If anybody is willing to look at the entire class diagram and tell me
> if I'm headed down the wrong path or possible have it correct, please
> do so. I'd be happy to email to you.
>
> On Mar 18, 9:00 am, John Andersen  wrote:
>
> > If I understand you correctly, then you consider the ZipLocation to be
> > the parent of the State?
>
> > My understanding of the situation is the reverse, one State may have
> > one or more ZipLocations, so one ZipLocation belongs to one State.
>
> > So your diagram looks correct with regard to the relationship between
> > ZipLocation and State :)
> > Enjoy,
> >    John
>
> > On Mar 18, 4:41 am, TheHerk  wrote:
>
> > > Here is a link to a screenshot of a class diagram I am working on,
> > > with noted model associations. There are several relationships in the
> > > diagram that feel wrong to me. The one in the diagram that illustrates
> > > this is between ZipLocation and State. In this case, state is
> > > enumerated in its own table. For some reason, to me, it seems strange
> > > that  ZipLocation, the parent, is belongsTo. I keep thinking in my
> > > head, “Each ZipLocation has one associated State,” but it doesn't seem
> > > to work that way. There are several more instances of this dilemma,
> > > but they are just the same.
>
> > >http://i8.photobucket.com/albums/a24/atomickeg/public/classes.png
>
> > > Does this look remotely correct?

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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

To unsubscribe from this group, send email to 
cake-php+unsubscribegooglegroups.com or reply to this email with the words 
"REMOVE ME" as the subject.


Re: Model Associations - just feels wrong

2010-03-18 Thread TheHerk
What you say makes sense. It makes sense to me that zip belong to
states because they really are the further breakdown. What I don't
understand is relations where child classes have many different
parents. I assume I am just over-thinking it, as per usual. Maybe it
really is as simple as it seems. Thank you for your help.

If anybody is willing to look at the entire class diagram and tell me
if I'm headed down the wrong path or possible have it correct, please
do so. I'd be happy to email to you.

On Mar 18, 9:00 am, John Andersen  wrote:
> If I understand you correctly, then you consider the ZipLocation to be
> the parent of the State?
>
> My understanding of the situation is the reverse, one State may have
> one or more ZipLocations, so one ZipLocation belongs to one State.
>
> So your diagram looks correct with regard to the relationship between
> ZipLocation and State :)
> Enjoy,
>    John
>
> On Mar 18, 4:41 am, TheHerk  wrote:
>
>
>
> > Here is a link to a screenshot of a class diagram I am working on,
> > with noted model associations. There are several relationships in the
> > diagram that feel wrong to me. The one in the diagram that illustrates
> > this is between ZipLocation and State. In this case, state is
> > enumerated in its own table. For some reason, to me, it seems strange
> > that  ZipLocation, the parent, is belongsTo. I keep thinking in my
> > head, “Each ZipLocation has one associated State,” but it doesn't seem
> > to work that way. There are several more instances of this dilemma,
> > but they are just the same.
>
> >http://i8.photobucket.com/albums/a24/atomickeg/public/classes.png
>
> > Does this look remotely correct?

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: Model Associations - just feels wrong

2010-03-18 Thread John Andersen
If I understand you correctly, then you consider the ZipLocation to be
the parent of the State?

My understanding of the situation is the reverse, one State may have
one or more ZipLocations, so one ZipLocation belongs to one State.

So your diagram looks correct with regard to the relationship between
ZipLocation and State :)
Enjoy,
   John

On Mar 18, 4:41 am, TheHerk  wrote:
> Here is a link to a screenshot of a class diagram I am working on,
> with noted model associations. There are several relationships in the
> diagram that feel wrong to me. The one in the diagram that illustrates
> this is between ZipLocation and State. In this case, state is
> enumerated in its own table. For some reason, to me, it seems strange
> that  ZipLocation, the parent, is belongsTo. I keep thinking in my
> head, “Each ZipLocation has one associated State,” but it doesn't seem
> to work that way. There are several more instances of this dilemma,
> but they are just the same.
>
> http://i8.photobucket.com/albums/a24/atomickeg/public/classes.png
>
> Does this look remotely correct?

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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


Re: Model Associations and Validations

2008-04-02 Thread Chris Hartjes

On Wed, Apr 2, 2008 at 4:55 PM, bmopro <[EMAIL PROTECTED]> wrote:
>
>  When i use the edit action in my user model i have the following to
>  grab the users info from the table...
>  $this->User->findById($id)
>  This returns an array that is HUGE!
>  It includes all my validation contained in my User model,
>  and all of the associations.  Obviously i just need the users info to
>  edit, i don't need all of the asociations.
>  I have looked at trying to use recursive but can't get it to work.

What do you mean "looked at trying to use recursive but can't get it to work".

$this->User->recursive = -1;
$this->User->findById($id);

-- 
Chris Hartjes
Internet Loudmouth
Motto for 2008: "Moving from herding elephants to handling snakes..."
@TheKeyBoard: http://www.littlehart.net/atthekeyboard

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



Re: Model associations to generate a history

2008-03-06 Thread Jon Bennett

>  http://cakeforge.org/projects/version/
>
>  You mean like that?

that would probably do the trick yes!

jb


-- 

jon bennett
w: http://www.jben.net/
iChat (AIM): jbendotnet Skype: jon-bennett

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



Re: Model associations to generate a history

2008-03-05 Thread nate

http://cakeforge.org/projects/version/

You mean like that?

On Mar 5, 5:51 pm, "Jon Bennett" <[EMAIL PROTECTED]> wrote:
> > I've been thinking about this recently, and I was thinking I would
> >  have a separate model to store the history, I was thinking
>
> >  id
> >  model
> >  foreign_key
> >  user_id
> >  type enum(new,update)
>
> >  you would then connect all your models to this one model using the
> >  foreign key, and only have 1 model to query to get a users history,
> >  rather than querying many and then having to sort those results.
>
> actually, I would definitely package this up as a behaviour - I'll
> post it up somewhere when it's done.
>
> jb
>
> --
>
> jon bennett
> w:http://www.jben.net/
> iChat (AIM): jbendotnet Skype: jon-bennett
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Model associations to generate a history

2008-03-05 Thread Jon Bennett

> I've been thinking about this recently, and I was thinking I would
>  have a separate model to store the history, I was thinking
>
>  id
>  model
>  foreign_key
>  user_id
>  type enum(new,update)
>
>  you would then connect all your models to this one model using the
>  foreign key, and only have 1 model to query to get a users history,
>  rather than querying many and then having to sort those results.

actually, I would definitely package this up as a behaviour - I'll
post it up somewhere when it's done.

jb



-- 

jon bennett
w: http://www.jben.net/
iChat (AIM): jbendotnet Skype: jon-bennett

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



Re: Model associations to generate a history

2008-03-05 Thread Jon Bennett

>  I'm trying to generate a Facebook-style Mini-feed about my users, so
>  that a profile page will have the general user information and also a
>  history of recent activity, which could be new favourites, new notes
>  about the user, etc.
>
>  How best to accomplish this?

I've been thinking about this recently, and I was thinking I would
have a separate model to store the history, I was thinking

id
model
foreign_key
user_id
type enum(new,update)

you would then connect all your models to this one model using the
foreign key, and only have 1 model to query to get a users history,
rather than querying many and then having to sort those results.

hth

jon


-- 

jon bennett
w: http://www.jben.net/
iChat (AIM): jbendotnet Skype: jon-bennett

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



Re: Model Associations Misbehave (very interesting)

2007-11-04 Thread Grant Cox

No no, the only issue is the recursive level.

When you query a model, by default the queries generated also include
that model's direct associations.  So, when you request a Topic you
also get the Posts (one level of association away).  But it doesn't
get the Users for those Posts, because that is two levels away from
the requested model.

If you want to adjust the levels of associations that are retrieved,
set the $recursive attribute of the model being queried.  So in your
case, something like

$this->Topic->recursive = 2;
$this->Topic->read(null, $topic_id);

will find the Topic, all of the Topic's associated Posts, and all of
those Posts' associated Users.


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



Re: Model Associations Misbehave (very interesting)

2007-11-04 Thread mbleonardo

Sorry, I just forgot to translate that part.

Now I changed everything to English, it matches the model and table
correctly.


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



Re: Model Associations Misbehave (very interesting)

2007-11-04 Thread mbleonardo

Sorry, I translated the table name to English and I forgot to change
that part.

It was written "Usuario" everywhere, but now I changed everything to
Users, and the problem continues the same way.


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



Re: Model Associations Misbehave (very interesting)

2007-11-04 Thread Felix Geisendörfer
Hey,
>   var $belongsTo = array('Usuario' =>
>array('className'  => 'Usuario',
>  'conditions' => '',
>  'order'  => '',
>  'foreignKey' => 'poster_id'
>)
>  );
'Usuario'? Change that to 'User' and try again.

-- Felix
--
Blogger: http://www.thinkingphp.org/
Entrepreneur: http://www.posttask.com/ /-- currently in private beta, 
ask me for invite / password/
Freelancer: http://www.fg-webdesign.de/

AIM:theundefined87
Skype:  TimeFor23
Other IM:   felixge.de 
Mobile (USA):   +1 404 3888693
Mobile (GER):   +49 162 9391612
Twitter:http://twitter.com/felixge




mbleonardo wrote:
> I'm making a simple Forum plugin to train with CakePHP.
>
> It has 4 models: Forum, Topic, Post and User:
>
> (You can pass by this part, I put it to explain better the problem)
>
>  class User extends ForumsAppModel {
>   var $name = 'User';
>   var $primaryKey = 'id';
> }
> ?>
>
>  class Forum extends ForumsAppModel {
>   var $name = 'Forum';
>   var $useTable = 'forum_forums';
>   var $primaryKey = 'forum_id';
> }
> ?>
>
>  class Topic extends ForumsAppModel {
>
>   var $name = 'Topic';
>   var $useTable = 'forum_topics';
>   var $primaryKey = 'topic_id';
>
>   var $hasMany = array('Post' =>
>array('className'  => 'Post',
>  'conditions' => '',
>  'order'  => '',
>'foreignKey' => 'topic_id'
>)
>  );
> }
> ?>
>
>  class Post extends ForumsAppModel {
>   var $name = 'Posts';
>   var $useTable = 'forum_posts';
>   var $primaryKey = 'post_id';
>
>   var $belongsTo = array('Usuario' =>
>array('className'  => 'Usuario',
>  'conditions' => '',
>  'order'  => '',
>  'foreignKey' => 'poster_id'
>)
>  );
> }
> ?>
>
> When I user the Topic model to get the posts for the model, the
> association Post-User doesn't work, generating these queries:
>
> Ps: I changed the column names by an asterisk to make this post
> cleaner.
>
> 1 - DESCRIBE `forum_topics`
> 2 - DESCRIBE `forum_posts`
> 3 - DESCRIBE `users`
> 4 - SELECT `Topic`.* FROM `forum_topics` AS `Topic` WHERE topic_id =
> 1
> 5 - SELECT `Post`.* FROM `forum_posts` AS `Post` WHERE
> `Post`.`topic_id` IN (1)
>
> ... but it generates the correct query when I use the Post Model
> directly:
>
> 1 - DESCRIBE `forum_posts`
> 2 - DESCRIBE `users`
> 3 - SELECT `Posts`.*, `User`.* FROM `forum_posts` AS `Posts` LEFT JOIN
> `users` AS `User` ON (`Posts`.`poster_id` = `User`.`id`) WHERE 1 = 1
>
> The correct queries should be:
>
> 1 - DESCRIBE `forum_topics`
> 2 - DESCRIBE `forum_posts`
> 3 - DESCRIBE `users`
> 4 - SELECT `Topic`.* FROM `forum_topics` AS `Topic` WHERE topic_id =
> 1
> 5 - SELECT `Posts`.*, `User`.* FROM `forum_posts` AS `Posts` LEFT JOIN
> `users` AS `User` ON (`Posts`.`poster_id` = `User`.`id`)
>
> I think the explanation for that behavior is: "Because Topics has many
> Posts, Posts belongs to Topics and cannot belong to Users"
>
> Is there a way to fix it, without using custom queries?? Thank you.
>
>
> >
>
>   

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



Re: Model associations problem

2007-08-07 Thread Luiz Paulo Nascimento

Did you already try 'conditions' => 'users.deleted = "0"' ?

The real table name is 'users', not 'User'...

[ ]'s
LP

2007/8/5, Ruud Gâst <[EMAIL PROTECTED]>:
>
> Hello there,
>
> I've got a simple construction of two models: users and familymembers;
> every user belongs to a familymember and a familymember has one user.
> So the database looks like this:
>
> `familymembers` (
>   `id` int(11) auto_increment,
>   `firstname` varchar(20),
>   `lastname` varchar(100),
>   `gender` tinyint(4),
>   `dob` date,
>   `email` varchar(100),
>   `created` datetime,
>   `deleted` tinyint(1)
> );
> `users` (
>   `id` int(11) auto_increment,
>   `familymember_id` int(11),
>   `username` varchar(20),
>   `password` varchar(255),
>   `deleted` tinyint(1),
>   `created` datetime
> );
>
> I'm using a hasOne association in the Familymember model, so it will
> only return one record ... great! But now I want to be able to keep
> old records, so if a user would be removed Users.deleted will be set
> to 1. Also great, so I thought, just fix the association so it will
> only return records where Users.deleted = 0. So I did that like this:
>
> var $hasOne = array(
>   'User' =>
> array(
>   'className' => 'User',
>   'conditions' => 'User.deleted = 0'
> )
>   );
>
> The CakePHP Manual says the following about hasOne associations:
>
> "We could use this to tell Cake to only associate a Profile that has a
> green header, if we wished. To define conditions like this, you'd
> specify a SQL conditions fragment as the value for this key:
> "Profile.header_color = 'green'"."  -http://manual.cakephp.org/
> chapter/models
>
> So in my case this model should only associate a Familymember that has
> not been deleted. But this simply doesn't work, Cake ignores the
> 'conditions'-part alltogether. I even tried to make conditions that
> would generate errors ... didn't get an error and none of the
> 'conditions' are included in the SQL-query.
>
> I've googled around to see if anyone else has a similar problem or
> similar system explained but haven't had any luck so far. So is there
> anyone who can tell me what I'm doing wrong, or even better, tell me
> how to do this the right way.
>
> Thanks!
>
> By the way: I'm using PHP 4.4 and CakePHP 1.1.14.4797
>
>
> >
>


-- 
Luiz Paulo Nascimento
[EMAIL PROTECTED]

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



Re: Model associations problem

2007-08-07 Thread Ruud Gâst

Well, the condition is not included in the SQL. So that is why I'm not
getting any errors when I create a condition that should create an
error...

I have removed all files in app/tmp/cache/models, if that is the right
way to clear the model caches then I have. If not, how can I do that?

Thanks for your reply,
Ruud


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



Re: Model associations problem

2007-08-06 Thread John David Anderson (_psychic_)


On Aug 6, 2007, at 4:49 PM, Ruud Gâst wrote:

>
> No-one has an answer? I'd say a lot of people use the same
> construction so it won't be that hard ... I just don't know how.

What happens when you turn DEBUG up to 2 or so? Does the SQL include  
the condition?

Have you tried clearing the model caches found in app/tmp/cache ?

-- John

>
> On Aug 6, 3:01 am, Ruud Gâst <[EMAIL PROTECTED]> wrote:
>> Hello there,
>>
>> I've got a simple construction of two models: users and  
>> familymembers;
>> every user belongs to a familymember and a familymember has one user.
>> So the database looks like this:
>>
>> `familymembers` (
>>   `id` int(11) auto_increment,
>>   `firstname` varchar(20),
>>   `lastname` varchar(100),
>>   `gender` tinyint(4),
>>   `dob` date,
>>   `email` varchar(100),
>>   `created` datetime,
>>   `deleted` tinyint(1)
>> );
>> `users` (
>>   `id` int(11) auto_increment,
>>   `familymember_id` int(11),
>>   `username` varchar(20),
>>   `password` varchar(255),
>>   `deleted` tinyint(1),
>>   `created` datetime
>> );
>>
>> I'm using a hasOne association in the Familymember model, so it will
>> only return one record ... great! But now I want to be able to keep
>> old records, so if a user would be removed Users.deleted will be set
>> to 1. Also great, so I thought, just fix the association so it will
>> only return records where Users.deleted = 0. So I did that like this:
>>
>> var $hasOne = array(
>>   'User' =>
>> array(
>>   'className' => 'User',
>>   'conditions' => 'User.deleted = 0'
>> )
>>   );
>>
>> The CakePHP Manual says the following about hasOne associations:
>>
>> "We could use this to tell Cake to only associate a Profile that  
>> has a
>> green header, if we wished. To define conditions like this, you'd
>> specify a SQL conditions fragment as the value for this key:
>> "Profile.header_color = 'green'"."  -http://manual.cakephp.org/
>> chapter/models
>>
>> So in my case this model should only associate a Familymember that  
>> has
>> not been deleted. But this simply doesn't work, Cake ignores the
>> 'conditions'-part alltogether. I even tried to make conditions that
>> would generate errors ... didn't get an error and none of the
>> 'conditions' are included in the SQL-query.
>>
>> I've googled around to see if anyone else has a similar problem or
>> similar system explained but haven't had any luck so far. So is there
>> anyone who can tell me what I'm doing wrong, or even better, tell me
>> how to do this the right way.
>>
>> Thanks!
>>
>> By the way: I'm using PHP 4.4 and CakePHP 1.1.14.4797
>
>
> >


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



Re: Model associations problem

2007-08-06 Thread Ruud Gâst

No-one has an answer? I'd say a lot of people use the same
construction so it won't be that hard ... I just don't know how.

On Aug 6, 3:01 am, Ruud Gâst <[EMAIL PROTECTED]> wrote:
> Hello there,
>
> I've got a simple construction of two models: users and familymembers;
> every user belongs to a familymember and a familymember has one user.
> So the database looks like this:
>
> `familymembers` (
>   `id` int(11) auto_increment,
>   `firstname` varchar(20),
>   `lastname` varchar(100),
>   `gender` tinyint(4),
>   `dob` date,
>   `email` varchar(100),
>   `created` datetime,
>   `deleted` tinyint(1)
> );
> `users` (
>   `id` int(11) auto_increment,
>   `familymember_id` int(11),
>   `username` varchar(20),
>   `password` varchar(255),
>   `deleted` tinyint(1),
>   `created` datetime
> );
>
> I'm using a hasOne association in the Familymember model, so it will
> only return one record ... great! But now I want to be able to keep
> old records, so if a user would be removed Users.deleted will be set
> to 1. Also great, so I thought, just fix the association so it will
> only return records where Users.deleted = 0. So I did that like this:
>
> var $hasOne = array(
>   'User' =>
> array(
>   'className' => 'User',
>   'conditions' => 'User.deleted = 0'
> )
>   );
>
> The CakePHP Manual says the following about hasOne associations:
>
> "We could use this to tell Cake to only associate a Profile that has a
> green header, if we wished. To define conditions like this, you'd
> specify a SQL conditions fragment as the value for this key:
> "Profile.header_color = 'green'"."  -http://manual.cakephp.org/
> chapter/models
>
> So in my case this model should only associate a Familymember that has
> not been deleted. But this simply doesn't work, Cake ignores the
> 'conditions'-part alltogether. I even tried to make conditions that
> would generate errors ... didn't get an error and none of the
> 'conditions' are included in the SQL-query.
>
> I've googled around to see if anyone else has a similar problem or
> similar system explained but haven't had any luck so far. So is there
> anyone who can tell me what I'm doing wrong, or even better, tell me
> how to do this the right way.
>
> Thanks!
>
> By the way: I'm using PHP 4.4 and CakePHP 1.1.14.4797


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



Re: Model Associations

2007-05-19 Thread Dr. Tarique Sani

On 5/19/07, hashkash <[EMAIL PROTECTED]> wrote:

> I would like to create an index page where he logs in and can see all
> equipment he owns.
> how do i associate the models??

Owner hasOne User or User belongsTo Owner

Read the manual to see which one suits your needs better

Tarique


-- 
My motto for everyone else -  "Just shut up, damnit!!"
=
PHP for E-Biz: http://sanisoft.com
=

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



Re: Model associations and cascading delete.

2007-01-05 Thread Tazz


Yes, I meant the constraints as they appear in the SQL table
definition. You pretty much answered my question. I use MYSQL...

My model is ass follows...

1 Newsletter has many Releases (Albums)

1 Release (Album) has many songs.

When I delete a newsletter I want it to delete all associated albums
and songs.

When I delete a specific album I want it to delete all associated
songs.

Though it doesn't seem to work. I set my dependent = true on my hasMany
association but it doesn't seem to work. I don't have the code at hand
right now...


the_woodsman wrote:

A few basic things, such as naming conventions and primary keys, are
all you generally need in your DB.

"Do I also have to setup the constrains in my database?"

Do you mean 'constraints' as they appear in SQL table definitions?
If you're referring to SQL commands such as REFERENCES, ON DELETE
CASCADE, etc, CakePHP might be able to use them to understand table
relationships  - I don't  know, the databases I use don't support this
syntax.

However you generally achieve these associations between tables at the
PHP level, by creating a few variables in the right classes to define
what other tables are linked to this one, and what these relationships
are.
In fact, this is much more powerful than the features available
directly in SQL!



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



Re: Model associations and cascading delete.

2007-01-04 Thread the_woodsman


A few basic things, such as naming conventions and primary keys, are
all you generally need in your DB.

"Do I also have to setup the constrains in my database?"

Do you mean 'constraints' as they appear in SQL table definitions?
If you're referring to SQL commands such as REFERENCES, ON DELETE
CASCADE, etc, CakePHP might be able to use them to understand table
relationships  - I don't  know, the databases I use don't support this
syntax.

However you generally achieve these associations between tables at the
PHP level, by creating a few variables in the right classes to define
what other tables are linked to this one, and what these relationships
are.
In fact, this is much more powerful than the features available
directly in SQL!


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



Re: Model associations and cascading delete.

2007-01-04 Thread Chris Hartjes


On 1/4/07, Tazz <[EMAIL PROTECTED]> wrote:


Does Cake do all the work? Or do I also have to setup the constrains in
my database?

Thanks



http://manual.cakephp.org/chapter/models

I believe the answer is "you have to setup the associations in your
code and make sure you create the associations in your tables".

Hope that helps.

--
Chris Hartjes

My motto for 2007:  "Just build it, damnit!"

rallyhat.com - digitial photo scavenger hunt
@TheBallpark - http://www.littlehart.net/attheballpark
@TheKeyboard - http://www.littlehart.net/atthekeyboard

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



Re: model associations with non-find functions

2006-12-06 Thread Jon Bennett

> Does $this->Model->recursive = -1 work like $this->Model->unbind(...)
> in that it only affects the next query?

yes. In fact, for you purpose they do exactly the same thing. The
beauty of the unbindAll method is it enables you to unbindAll butSome
associations with one method, which if you have many setup can be very
handy, though you'd only use on find() or findAll() not find();

If you want to unbind all associations before any retrieval methods
(find() findAll() generateList()) you can also set recursive = -1;

hth

jon

-- 


jon bennett
t: +44 (0) 1225 341 039 w: http://www.jben.net/
iChat (AIM): jbendotnet Skype: jon-bennett

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



Re: model associations with non-find functions

2006-12-06 Thread codecowboy

Thank you for your reply.  One question though.

Does $this->Model->recursive = -1 work like $this->Model->unbind(...)
in that it only affects the next query?


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



Re: model associations with non-find functions

2006-12-06 Thread Jon Bennett

> Ex.  If I use $this->Model->generateList(), do I need to precede it
> with $this->Model->unbindAll() in order to prevent Cake from grabbing
> all models associated with Model?

$this->Model->recursive = -1;
$this->Model->generateList();

jb

-- 


jon bennett
t: +44 (0) 1225 341 039 w: http://www.jben.net/
iChat (AIM): jbendotnet Skype: jon-bennett

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



Re: model associations causing errors.

2006-06-30 Thread Samuel DeVore
Try using array('Article.active'=1) for the condition ('Article.active'=1 would work as well but there are some advantages to using the arrays for conditions)On 6/30/06, 
AD7six <[EMAIL PROTECTED]> wrote:
Hi Luke,set debug to 2 in your /app/config/core.php file, and you will see thatthe sql query that is generated, and see that there are 2 tablesincluded in the SQL that contain the field active.
Cheers,AD7six
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.  To post to this group, send email to cake-php@googlegroups.com  To unsubscribe from this group, send email to [EMAIL PROTECTED]  For more options, visit this group at http://groups.google.com/group/cake-php  -~--~~~~--~~--~--~---


Re: model associations causing errors.

2006-06-30 Thread AD7six

Hi Luke,

set debug to 2 in your /app/config/core.php file, and you will see that
the sql query that is generated, and see that there are 2 tables
included in the SQL that contain the field active.

Cheers,

AD7six


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/cake-php
-~--~~~~--~~--~--~---