I have a User
model and a Task
model. I have not mentioned any relation between them while creating them.
I need to establish that U
The Relationship in Rails is taken care by model not by Rails.
So you just need to define this relationship in your model:
class User < ActiveRecord::Base
has_many :tasks
end
class Task < ActiveRecord::Base
belongs_to :user
end
And just make sure that a user_id
field is present in the migration for creating the "tasks" table.