problem on belongsTo many models

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

problem on belongsTo many models

exiang

Here is the scenario:

1)
An Area have many schools
A school belongs to an area

2)
A school have many equipments
An area have many equipments too
Thus, an equipment can belongs to either a school or an area (as in
belongs to the office of the area that govern all school)

3)
i have db table and models for area, school and equipment

4)
when an equipment belongs to a school, its area_id field will marked 0
when an equipment belongs to an area, its school_id field will marked
0

How can i define the belongsTo in Equipment class to work in my
requirement?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: problem on belongsTo many models

Richard@Home

If I'm understanding correctly:

You will need to set up two associations:

in model equipment:

$belongsTo = array('school', 'area');

(make sure the school and area arguments above appear in the same
order as their school_id and area_id in the table)

On a related note, I'm not sure that's the best schema to represent
your data and the logic requirements.


On Feb 7, 3:19 am, "exiang" <[hidden email]> wrote:

> Here is the scenario:
>
> 1)
> An Area have many schools
> A school belongs to an area
>
> 2)
> A school have many equipments
> An area have many equipments too
> Thus, an equipment can belongs to either a school or an area (as in
> belongs to the office of the area that govern all school)
>
> 3)
> i have db table and models for area, school and equipment
>
> 4)
> when an equipment belongs to a school, its area_id field will marked 0
> when an equipment belongs to an area, its school_id field will marked
> 0
>
> How can i define the belongsTo in Equipment class to work in my
> requirement?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: problem on belongsTo many models

exiang

Nop, it doesn't work.
As i understand, belongsTo will create a join table in sql.

However, in this case,

an equipment  can belongs to a school or an area, but not both



On Feb 8, 1:37 am, "RichardAtHome" <[hidden email]> wrote:

> If I'm understanding correctly:
>
> You will need to set up two associations:
>
> in model equipment:
>
> $belongsTo = array('school', 'area');
>
> (make sure the school and area arguments above appear in the same
> order as their school_id and area_id in the table)
>
> On a related note, I'm not sure that's the best schema to represent
> your data and the logic requirements.
>
> On Feb 7, 3:19 am, "exiang" <[hidden email]> wrote:
>
> > Here is the scenario:
>
> > 1)
> > An Area have many schools
> > A school belongs to an area
>
> > 2)
> > A school have many equipments
> > An area have many equipments too
> > Thus, an equipment can belongs to either a school or an area (as in
> > belongs to the office of the area that govern all school)
>
> > 3)
> > i have db table and models for area, school and equipment
>
> > 4)
> > when an equipment belongs to a school, its area_id field will marked 0
> > when an equipment belongs to an area, its school_id field will marked
> > 0
>
> > How can i define the belongsTo in Equipment class to work in my
> > requirement?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake PHP" group.
To post to this group, send email to [hidden email]
To unsubscribe from this group, send email to [hidden email]
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: problem on belongsTo many models

Boys32
This post has NOT been accepted by the mailing list yet.
Problem solving is an essential thing that kids should be taught right from early childhood. There are various fun methods for teaching problem solving activities. You can use interesting models too. You can get some cool ideas for 1st to 8th standard at http://www.kidsfront.com/class/8th-class.html.
Loading...