Answers for "inverse of in rails"

0

inverse of in rails

class Project < ActiveRecord::Base
  has_many :tasks, :inverse_of=>:project
end

class Task < ActiveRecord::Base
  belongs_to :project, :inverse_of=>:tasks
end
Posted by: Guest on May-30-2021
0

inverse of in rails

irb> p = Project.new
=> #<Project id: nil, name: nil, ...>
irb> t = p.tasks.build
=> #<Task id: nil, project_id: nil, ...>
irb> t.project
=> #<Project id: nil, name: nil, ...>
Posted by: Guest on May-30-2021

Browse Popular Code Answers by Language