I have 4 clases, with an STI on Instance.
Workspace, Project, Task, Instance, (type1 < Instance) and (type2 < Instance).
With proper associations. (Workspace has_many projects, has_many task through projects, so on)
And I have this nested create (worked before implementing STI):
if (%w(type1 type2).include?(params[:type]))
sti_class = params[:type].classify.constantize
workspaces.find_by_name(name: w_name).
projects.where( name: p_name).first_or_create!.
tasks.where(name: t_name).first_or_create!.
sti_class.create()
now, that doesn't work, I can't figure out a way.
However, the following works, but I want to keep the nested create.
task= workspaces.find_by_name(name: w_name).
projects.where( name: p_name).first_or_create!.
tasks.where(name: t_name).first_or_create!
sti_class.create(task_id: task.id)
How can I keep the nested create?