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 Dec 22, 9:16 am, John S. [email protected]
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
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?
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. <
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.:
(go to parts 2 and 3 after you’re done with part 1).
On Dec 22, 5:56 am, John S. [email protected]
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?
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.
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.:
#73 Complex Forms Part 1 - RailsCasts
(go to parts 2 and 3 after you’re done with part 1).On Dec 22, 5:56�am, John S. [email protected]
Thanks a lot. I will check it.