Weights belongsTo both Categories and Courses
Categories hasMany Weights
Courses hasMany Weigths
BelongsTo means the model that belongsTo something also has the
foreign keys "in itself" (Weights.course_id).
For hasMany THE OTHER model is supposed to have the foreign key
(Courses hasMany Weights, so Courses will look for a
Weights.category_id that matches its own id).
Behold my ASCII art: ;-)
/ Weight.category_id
Category.id - Weight.category_id
\ Weight.category_id
HasMany and belongsTo are the two sides you need for a single-many
relationship.
hasAndBelongsToMany expresses a many-many relationship, with both
models havingAndBelongingToMany.
A hasOne-belongsTo pair would be a one-one relationship.
Does that help?
On 12 Sep 2008, at 22:42, soldier.coder wrote:
>
> I am getting lost in semantics and need a guide. I'm writing an app
> that keeps track of grades for students in multiple courses.
> Depending on the type of course, there will be different categories of
> grades ('Lab Assignments','Oral Presentation', 'Programming
> Assignments', ...) and there will be different weights for the grades
> of different categories. So let me lay out some tables:
>
> Weights table
> course_id
> category_id
> number
> weight
>
> Categories table
> category_id
> description
>
> Courses
> course_id
> course_name
>
>
> So it is obvious to me that the Weights table "belongs to" the Courses
> and Categories tables.
> When I set up the weights that is strait forward to me. My problem
> comes when I start thinking about how to write the model for the
> Categories table. According to a book I am reading, "each relationship
> with association mapping must be specified in both directions" and
> when describing the "other direction" in the relationship between
> Categories and Weights or between Categories and Courses I have
> exactly 3 options: "Has One", "Has Many" and "Has and Belongs To
> Many"...
>
> Which is right for the relationship between Categories and Weights?
> and why?
> Which is right for the relationship between Categories and Courses?
> and why?
>
> Thank you very much for your help!
>
>
> >
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---