Hi,
I have an hmbtm relationship setup like:
class Catogory < ActiveRecord::Base
has_many_belongs_to_many: products
end
class Product < ActiveRecord::Base
has_many_belongs_to_many: categories
end
With the usual SQL tables (i.e., categories, products,
categories_products).
NOTE: I AM USING MICROSOFT SQL SERVER -- that might be the source of my
issues...
All my ids are int identity(1, 1) not null in SQL. I quit using
uniqueidentifier as Rails gets very confused.
I cannot add a Product<->Category relationship via Rails, like:
aProduct = Product.find(41234)
P.categories << aCategory
It throws an exception coming from SQL:
Execute
OLE error code:80040E14 in Microsoft OLE DB Provider for SQL Server
Line 1: Incorrect syntax near '')''.
HRESULT error code:0x80020009
Exception occurred.: INSERT INTO partners_recipients () VALUES ()
While it is obvious the SQL statement fails, I don''t understand why
Rails generated this buggy statement.
If I had the relationship by hand in SQL, I can perfectly issue a find
in Rails or retrieve it.
>From the source code, it looks like:
File:
activerecord-1.11.1.1962\lib\active_record\associations\has_and_belongs_
to_many_association.rb
Method: insert_record
Lines 121 and 123 seem to work as I get something in the breakpointer.
And I guess line 139, since I cannot make the @owner.send work:
"INSERT INTO #{@join_table}
(#{@owner.send(:quoted_column_names, attributes).join('', '')})
" +
"VALUES (#{attributes.values.join('',
'')})"
Fails.
More specifically: @owner.send(:quoted_column_names, attributes)
>From my debug in irb, it sounds like attribute contains Strings (at
least in my case) and they don''t accept a :quoted_column_names method,
at least I can''t find that method.
Am I missing a patch, or something?!?
Thanks,
Gildas