Topic: Model Reuse Question

I currently have the following artifacts :

+ Project model
+ TodoList model
+ Task model

Each Project can have many Tasks, and the TodoList can have many Tasks.
I want the application to allow the user to create a project/todolist, then edit it to add its associated tasks.

My question is that, do I need a new controller/view/model for the middleware to set up those
associations. For instance, do I need a ProjectTask model and a TodoList model (with associated controller/view) ?

Any help on this would be much appreciated. Also, if you need any clarification, please ask and I will give any details I can.


Re: Model Reuse Question

You could just add 2 models. You would not need to add a controller or view for these join models. This isn't necessarily how I would do it but the models could look like this:

Project Model
has_many :project_tasks
has_many :tasks :through => :project_tasks

-- ProjectsTasks
belongs_to :project
belongs_to :task

has_many :project_tasks
has_many :projects :through => :project_tasks

belongs_to :todo_list
belongs_to :task

has_many :todo_list_tasks
has_many :tasks :through => :todo_list_tasks


Re: Model Reuse Question

Thank you for your response.

So, let's say that I have a form to edit a project/todolist model. This form will
allow me to also create new tasks via a link_to to the task controller. Don't I need a
seperate controller/view for each case where I create the project->task and todolist-> task
association ?

Re: Model Reuse Question

As far as i know..
if your association is a one to many or one to one..
you wont need a separate model
just specify has_many and belongs_to what not in the model..
and also the relevant id data in the database table..

but if you were to do a many to many association
there is a case where you need an intermediate model... which is called has_many :through … ssociation
guess this will give you a clearer idea~