I have this problem. I have a Job table in my db, and each job has many steps (table Step). Is not possible to know how many steps a job has until it is created. So when I create a new job I have a problem: I can not have a step_id in my Job table, because it can be one step or more. What can I do?
on 2008-12-22 11:16
on 2008-12-22 11:21
On Dec 22, 9:16 am, John S. <email@example.com> wrote: > I have this problem. > I have a Job table in my db, and each job has many steps (table Step). > Is not possible to know how many steps a job has until it is created. So > when I create a new job I have a problem: I can not have a step_id in my > Job table, because it can be one step or more. > What can I do? If jobs has_many :steps then the jobs table doesn't have a step_id at all: steps have a job_id column. Fred
on 2008-12-22 11:29
Thanks, I know. If I can create a job first I have no problem, but I can't do that. I want to be able to create a job and, at the same time, create as many steps as I want. I would use AJAX in order to create new step fields, but if I have not created a job I can have any relation between a step and a job. Any ideas?
on 2008-12-22 12:44
HAii.. sorry my English is very bad I don't what you want... but I have idea why do u not use 3 model / 3 table? table job id table join_job_step job_id step_id table step id this is "has_many_and_belongs_to" (same), but Don't use "has_many_and_belongs_to". Model: * job has_many :join_job_steps * join_job_step belongs_to :job * step has_may :join_job_steps So, when u create job or step, u don't need step_id or job_id.. And if u want make relation, just create join_job_step. May be it can help u... Thank you -- Wu You Duan(Anton effendi) Senior Rails Developer www.kiranatama.com On Mon, Dec 22, 2008 at 4:29 PM, John S. <
on 2008-12-22 12:56
Thanks a lot, but I think that does not solve my problem, because I need to create a job to make a relation between the job and it steps. With that, I can create steps without a job, but how can I make relation between these steps and the job. Should I have to take the last steps and make a relation with the job I am creating? I think this is a bas solution. Any other ideas?
on 2008-12-22 18:09
I think what you're looking for is the build method, something along the lines of @job.steps.build in your controller. Take a look at the complex form railscasts by Ryan B.: http://railscasts.com/episodes/73-complex-forms-part-1 (go to parts 2 and 3 after you're done with part 1). On Dec 22, 5:56 am, John S. <firstname.lastname@example.org>
on 2008-12-23 09:57
Harold wrote: > I think what you're looking for is the build method, something along > the lines of @job.steps.build in your controller. > > Take a look at the complex form railscasts by Ryan B.: > http://railscasts.com/episodes/73-complex-forms-part-1 > (go to parts 2 and 3 after you're done with part 1). > > > On Dec 22, 5:56ï¿½am, John S. <email@example.com> Thanks a lot. I will check it.
on 2008-12-23 12:42
sorry to say, but i think what you really need is a guide on data- modeling. if a job has many steps, the job has to be there before you create any steps, as every step belongs to exactly one job. now, you say you have to create a job and its steps at the same time. why don't you think of a way to solve that? look into your controller, there is always a solution.