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


Model Associations Question

2012-06-26 Thread Sanfly
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: Simple Model Associations Question

2007-05-23 Thread Brian Hartvigsen

For the scaffolding to show the description instead of the id you need
to add this to your Status/Priority model:
 var $displayField = 'description';

and to accomplish what you are wanting with Status/Priority I had to
make it a $belongsTo instead of a $hasOne ($hasOne expects the Status
& Priority tables to have a item_id foreign key.)  Seems odd, but
that's the only way I know to make it work, but I have about the same
amount of experience as you ;)

Hope that helps!

-- Brian

On May 23, 7:00 am, "Howard Glynn" <[EMAIL PROTECTED]> wrote:
> been using cake a fortnight or so, very impressed, i'm up and running and
> it is saving heaps of time  :-) ... but looking for a little clarificaton
>
> Say I have a model called "Items" which is my main table of data.
> This contains a couple of foreign keys, say "status_id" and "priority_id"
>
> "Statuses" and "Priorities" contain two fields, id and description
> (these occasionally get changed and updated, especially by admin users,
> which is why they need their own models to update via web form)
>
> I think it is an M:1 relationship from Items to Statuses [or Priorities]
> (i.e. Many different Items can have the same status [or priority])
>
> In Items, and this class alone, I say something like below. Is
> this the right relationship descriptor? Does "Statuses" need anything?
> I've tried reading the docs but i can't quite get my head round it.
>
> var $hasOne = array(
> 'Status' =>
> array('className' => 'Status',
> 'foreignKey' => 'id',
> 'conditions' => '',
> 'fields' => '',
> 'order' => '',
> 'dependent' => 'false'
> ),
>
> If I do this, what can I expect? I was kind of hoping the scaffolding would
> replace
> the numeric id's in the basic form with the descriptive versions (maybe that
> is asking
> a little too much!)  Is it the case that the data is in the variable on the
> page, i just need
>
> Ta, HG


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Simple Model Associations Question

2007-05-23 Thread Howard Glynn
been using cake a fortnight or so, very impressed, i'm up and running and
it is saving heaps of time  :-) ... but looking for a little clarificaton

Say I have a model called "Items" which is my main table of data.
This contains a couple of foreign keys, say "status_id" and "priority_id"

"Statuses" and "Priorities" contain two fields, id and description
(these occasionally get changed and updated, especially by admin users,
which is why they need their own models to update via web form)

I think it is an M:1 relationship from Items to Statuses [or Priorities]
(i.e. Many different Items can have the same status [or priority])

In Items, and this class alone, I say something like below. Is
this the right relationship descriptor? Does "Statuses" need anything?
I've tried reading the docs but i can't quite get my head round it.

var $hasOne = array(
'Status' =>
array('className' => 'Status',
'foreignKey' => 'id',
'conditions' => '',
'fields' => '',
'order' => '',
'dependent' => 'false'
),

If I do this, what can I expect? I was kind of hoping the scaffolding would
replace
the numeric id's in the basic form with the descriptive versions (maybe that
is asking
a little too much!)  Is it the case that the data is in the variable on the
page, i just need

Ta, HG

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---