der_tom
(der_tom)
March 28, 2017, 5:37pm
1
hi,i am trying to use ror on a legacy system.
model:
belongs_to :ProvincialTaxAreaCode, class_name: “TaxArea”, foreign_key: “ProvincialTaxAreaCode” #, primary_key: “ProvincialTaxAreaCode”
ProvincialTaxAreaCode is a varchar(20)
html-slect:
test- 123
error:
ActiveRecord::AssociationTypeMismatch (TaxArea(#109333370 ) expected, got String(#70918210 )):
how can i still use the varchar field without converting it???
hassan
(Hassan Schroeder)
March 28, 2017, 6:55pm
2
?? A model "belongs_to" another model, not a string.
This might help:
der_tom
(der_tom)
March 28, 2017, 7:05pm
3
where do you see a string?
association is called :ProvincialTaxAreaCode (because of simple_form_for
the associated class is called TaxArea
the fkey is ProvincialTaxAreaCode (varchar20)
hassan
(Hassan Schroeder)
March 28, 2017, 8:12pm
4
where do you see a string?
To repeat quoting you:
model:
belongs_to :ProvincialTaxAreaCode
ProvincialTaxAreaCode is a varchar(20)
Did you look at the Rails guide link I included?
Hi. You should use different names for association and for foreign key for this association. Looks like they are overlapping, just rename association name to fit ar conventions - and it should work.