Monday, October 4, 2010

HABTM

I'm looking for help with associations, specifically HABTM. What if
you have more than one HABTM for a model? The parser won't allow it.
So what to do? The manual doesn't seem to answer this question or
perhaps it does but I didn't see it.


This is my setup: If anybody can point our where I am mistaken I would
be so grateful....


I'm setting up a bookshelf application. My models are: Book, Author,
Publisher, Tag

In my scenario here is the logic:

- Book can have one or more Author
- Author can have one or more Book
- Book can have one Publisher
- Publisher can have one or more Book
- Book can have one or more Tag
- Tag can have one or more Book

In my model classes I have set the associations up as follows

class Book extends AppModel{
var $hasAndBelongsToMany = 'Author';
var $belongsTo = 'Publisher';
}

class Author extends AppModel{
var $hasAndBelongsToMany = 'Book';
}

class Publisher extends AppModel{
var $hasMany = 'Book';
}

class Tag extends AppModel{
var $hasAndBelongsToMany = 'Book';
}

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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: