Quantcast

Multiple Database relations (HABTM and HasMany)?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Multiple Database relations (HABTM and HasMany)?

InJu
Hi everybody,

this my first time working with CakePHP and my first big PHO project as well.

I want to build the Model associations between a User and Task database. Every user has many tasks and a task can be linked to many users. As I understand HABTM-Relations this should be one. But I also want to save the User who created the task. This is a hasMany relation. My question is now, how does the models for Users and Tasks look like?

Thanks in advance!

--
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
 
 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Multiple Database relations (HABTM and HasMany)?

Andrew Johnston
I won't write out the models (too tired), but I'll give you the DB structure and you can base the models off that:
Table: users
id (primary key)
username
pass

Table: tasks
id (primary key)
user_id  <--- This is the user that created the task

Table users_tasks
id (primary key)
user_id
task_id

This way, given a certain task you can find the creator and all of the people assigned to the task. 

On Sunday, August 19, 2012 8:50:52 PM UTC-4, InJu wrote:
Hi everybody,

this my first time working with CakePHP and my first big PHO project as well.

I want to build the Model associations between a User and Task database. Every user has many tasks and a task can be linked to many users. As I understand HABTM-Relations this should be one. But I also want to save the User who created the task. This is a hasMany relation. My question is now, how does the models for Users and Tasks look like?

Thanks in advance!

--
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/cake-php?hl=en-US.
 
 
Loading...