I have a Task model:
## Task
has_many :children, :class_name => "Task"
belongs_to :parent, :class_name => "Task", :foreign_key => "parent_id"
Basically user has many tasks and each task has many child tasks.
I did this inside a view:
<%= render @tasks %>
And it used to work fine when the data structure was one dimensional.
However I keep getting the error message "(SQLite3::SQLException: no such column: tasks.task_id: SELECT "tasks".* FROM "tasks" WHERE "tasks"."task_id" = 138)" after adding the associations. I was expecting "parent_id", since that's what the model is supposed to refer to.
I am guessing that this is because of how rails implicitly connects the local variable "task" with its class "task". For example, I want to build a form inside comment like so:
## inside _task.html.erb
<%= form_for task.children.build do |f| %>
<%= f.text_area :description %>
<% end %>
But it doesn't work because task.children gets an error saying that task doesn't have a column "task_id", when it's supposed to refer to "parent_id". Is there a way around this problem?