Have you considered something like:

Bookmark
  hasOne Content
Message
  hasOne Content
Post
  hasOne Content

Content
  belongsTo Bookmark
    foreignKey => 'model_id'
    conditions 'model' => 'Bookmark'
  belongsTo Message
    foreignKey => 'model_id'
    conditions 'model' => 'Message'
  belongsTo Post
    foreignKey => 'model_id'
    conditions 'model' => 'Post'

This results in four model classes, none of which require inheritance/
extending/subclassing. To get all bookmarks with their respective
content, you can simply (assuming you've attached the
ContainableBehavior to the Bookmark model):

  $this->Bookmark->find('all', array(
    'contain' => 'Content'
  );

and the resulting array would be something like

  Array
  (
    [0] => Array
      (
        [Bookmark] => Array
          (
            [id] => 1
            [url] => http://www.example.com
            [message] => Examples
          )
        [Content] => Array
          (
            [id] => 5
            [user_id] => 51
            [target_id] => 73
            [category_id] => 54
            [model] => Bookmark
            [model_id] => 1
            [created] => 2011-02-11 10:32:41
            [modified] => 2011-02-11 10:32:41
          )
    [1] => ...
  )

Note that the individual tables books, messages, posts DOES NOT have a
content_id field, but the contents table would have the fields 'model'
and 'model_id'.  This results in a content record that can only be ONE
of either book, message, or post.  In your proposed table schema,
where all three tables have content_id, you would have a content
record that can be any or all of the above, which is probably not what
you want.


On Feb 10, 10:32 am, mfrday <[email protected]> wrote:
> Thanks for the reply Sam.   I don't think I will have shared
> functionality per se, but I am trying to avoid putting all of the
> fields that are in the content table on each of the other tables /
> classes.   I was thinking it would be best to use a single base class
> & db table to store all of the shared information about any content
> record in the system.
>
> Based on the two links, I believe the second one is exactly what I am
> looking for.   I'm just not sure how to implement it.
>
> Thanks again.,
>
> On Feb 10, 8:21 am, Sam Sherlock <[email protected]> wrote:
>
>
>
> > what functionality does the content class give the classes that extend it?
>
> > I think you want to have these reusable parts within a component
> > and use behaviours on the corresponding models
>
> > but you can read Neil Crook's answer 
> > herehttp://stackoverflow.com/questions/1875831/cakephp-abstracting-appcon...
> > also 
> > readhttp://cakephp.1045679.n5.nabble.com/Extending-controllers-td1261319....
>
> >  - S
>
> > On 9 February 2011 20:28, mfrday <[email protected]> wrote:
>
> > > Hi there - I am somewhat of a newbie to cake, and have what I believe
> > > is a simple question.     I have the following content entities being
> > > submitted to our system:   bookmarks, messages, and posts.   All of
> > > these entities have a set of underlying similar fields /
> > > relationships.   What I would like to do is create a base class
> > > (content) that can be inherited by all of these other content
> > > entities.
>
> > > Here is a sample of the data elements:
>
> > > Contents Class:
> > > - id
> > > - user_id
> > > - target_id
> > > - category_id
> > > - created
> > > - modified
>
> > > Bookmarks Class (inherits from Content)
> > > - id
> > > - content_id
> > > - url
> > > - message
>
> > > Posts Class  (inherits from Content)
> > > - id
> > > - content_id
> > > - name
> > > - picture
>
> > > etc....
>
> > > My question is how do I go about doing this ?   Is the Content class a
> > > component ?   Do I need to create a regular view / controller for it
> > > as well ?
>
> > > Any direction that could be given would be extremely helpful.
>
> > > Regards,
>
> > > --
> > > Our newest site for the community: CakePHP Video Tutorials
> > >http://tv.cakephp.org
> > > Check out the new CakePHP Questions sitehttp://ask.cakephp.organdhelp
> > > others with their CakePHP related questions.
>
> > > To unsubscribe from this group, send email to
> > > [email protected] For more options, visit this group
> > > athttp://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
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to