Re: Basic association question, extending models...

2008-01-16 Thread Chris Gallop

Appreciate the clarification, points me in the right direction.
Thanks.

On Jan 16, 8:58 pm, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> In their basic form, models in Cake are a way of accessing SQL-data.
> They may also contain any number of other data-manipulation
> functionality that may be relevant. They do not represent the data in
> the same direct way you are used to. They represent a way of accessing
> and manipulating the data.
>
> The frame of mind used in the design of ActiveRecord (Models in Cake)
> is one of data having and belonging to other data... not being a
> subset or superset of as in classic 'Apples are a form of fruit' -type
> of inheritance.
>
> That is one reason why data is returned by model and not "mixed in".
> Your Client is not a Person, he belongs to a Person. See the
> difference? Think of it in terms of a Person having "Client-
> capabilities" and a "Client-membership" belonging to a Person.
>
> To get data-inheritance you will have to build some logic info your
> Models. You will loose a lot of the automagic that Cake does so well.
> I do not recommend it unless it is absolutely vital to your
> application.
>
> I have not done any similar code but in simple meta:
> afterFind() - takes each returned record and for each association adds
> that data to the main models dataset taking care not to overwrite any
> identically named fields. The id is always going to be a problem.
> beforeSave() - you do the reverse. Extract the assoc-data from the
> main dataset.
>
> Not a lot of fun.
>
> On Jan 15, 11:58 pm, Chris Gallop <[EMAIL PROTECTED]>
> wrote:
>
> > I am just trying to get some clarity on associations.  I've done a
> > little object orientated programming before and in cake it seems a
> > little different in regard to extending objects.  In my case I have a
> > table for people, clients and suppliers.  Obviously people contains
> > basic info like name, address, phone etc.  Client would contain
> > company name, discount rate etc. Supplier would contain other supplier
> > related info.  In the past I would build a model so that the 'client'
> > extends the 'person' class.
>
> > In cake I understand you use 'belongsTo'.  So I would setup my client
> > model with a belongsTo association (to person).  So when I load up the
> > client I can access all their 'person' (table) information as well?
> > The only different being rather than getting the address of a client
> > this way $data['client']['address'], I get it $data['person']
> > ['address'].  Is this correct and is this the best method for
> > 'extending' classes (using the belongsTo association).
>
> > Thanks for any advice I may have missed here.

--~--~-~--~~~---~--~~
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: Basic association question, extending models...

2008-01-16 Thread [EMAIL PROTECTED]


In their basic form, models in Cake are a way of accessing SQL-data.
They may also contain any number of other data-manipulation
functionality that may be relevant. They do not represent the data in
the same direct way you are used to. They represent a way of accessing
and manipulating the data.

The frame of mind used in the design of ActiveRecord (Models in Cake)
is one of data having and belonging to other data... not being a
subset or superset of as in classic 'Apples are a form of fruit' -type
of inheritance.

That is one reason why data is returned by model and not "mixed in".
Your Client is not a Person, he belongs to a Person. See the
difference? Think of it in terms of a Person having "Client-
capabilities" and a "Client-membership" belonging to a Person.

To get data-inheritance you will have to build some logic info your
Models. You will loose a lot of the automagic that Cake does so well.
I do not recommend it unless it is absolutely vital to your
application.

I have not done any similar code but in simple meta:
afterFind() - takes each returned record and for each association adds
that data to the main models dataset taking care not to overwrite any
identically named fields. The id is always going to be a problem.
beforeSave() - you do the reverse. Extract the assoc-data from the
main dataset.

Not a lot of fun.



On Jan 15, 11:58 pm, Chris Gallop <[EMAIL PROTECTED]>
wrote:
> I am just trying to get some clarity on associations.  I've done a
> little object orientated programming before and in cake it seems a
> little different in regard to extending objects.  In my case I have a
> table for people, clients and suppliers.  Obviously people contains
> basic info like name, address, phone etc.  Client would contain
> company name, discount rate etc. Supplier would contain other supplier
> related info.  In the past I would build a model so that the 'client'
> extends the 'person' class.
>
> In cake I understand you use 'belongsTo'.  So I would setup my client
> model with a belongsTo association (to person).  So when I load up the
> client I can access all their 'person' (table) information as well?
> The only different being rather than getting the address of a client
> this way $data['client']['address'], I get it $data['person']
> ['address'].  Is this correct and is this the best method for
> 'extending' classes (using the belongsTo association).
>
> Thanks for any advice I may have missed here.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Basic association question, extending models...

2008-01-15 Thread Chris Gallop

I am just trying to get some clarity on associations.  I've done a
little object orientated programming before and in cake it seems a
little different in regard to extending objects.  In my case I have a
table for people, clients and suppliers.  Obviously people contains
basic info like name, address, phone etc.  Client would contain
company name, discount rate etc. Supplier would contain other supplier
related info.  In the past I would build a model so that the 'client'
extends the 'person' class.

In cake I understand you use 'belongsTo'.  So I would setup my client
model with a belongsTo association (to person).  So when I load up the
client I can access all their 'person' (table) information as well?
The only different being rather than getting the address of a client
this way $data['client']['address'], I get it $data['person']
['address'].  Is this correct and is this the best method for
'extending' classes (using the belongsTo association).

Thanks for any advice I may have missed here.

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