Robson Montenegro

Joined

50 Experience
0 Lessons Completed
0 Questions Solved

Activity

Stuck in a - at first sight - simple problem in RoR. I have two ActiveRecord models: Foo has many Bars.. But I want to bind them by "custom_id" (not the default id):

class Foo < ApplicationRecord
  has_many :bars, :class_name => "Bar", :foreign_key => "custom_id"
end

class Foo < ApplicationRecord
  has_many :bars, :class_name => "Bar", :foreign_key => "custom_id"
end

Given that, I'd guess this pass would PASS, but it doesnt:

foo = Foo.new(:id=> 1, :custom_id => 100)
bar = Bar.new(:foo=>foo)

assert bar.custom_id == foo.custom_id # bar.custom_id == 1 and foo.custom_id == 100

The code is here: https://github.com/montenegrodr/temporary_repository_ror