rowland/activerecord-fb-adapter

Problem with many to many assiocation

ja-win opened this issue · 2 comments

Hello Rowland,

at first a great thanks to you, for your fb and activerecord-fb-adapter gem.

I have a problem with managing many to many assiocations.

I have 2 Models(Article & Material) which are connected with a has_and_belongs_to_many assication

When i want to add a material to an article in the rails console i get this error:

Code:
article.materials = material_i_want_to_set

Error:

ActiveRecord::StatementInvalid: Fb::Error: The insert failed because a column definition includes validation constraints.
validation error for column ID, value "*** null ***"
: INSERT INTO "ARTICLES_MATERIALS" ("ARTICLE_ID", "MATERIAL_ID") VALUES (1, 1)

is this a bug?

thanks for your help

A normal HABTM table does not have an ID column, but perhaps yours does? That would cause an error like this one. The only reason you would need an ID column is if you have fields in addition to the foreign keys. In that situation, you would setup has-many-through associations, instead of has-and-belongs-to-many.

Hope this helps.

Brent

On Aug 22, 2013, at 8:05 AM, Camouflagezebra wrote:

Hello Rowland,

at first a great thanks to you, for your fb and activerecord-fb-adapter gem.

I have a problem with managing many to many assiocations.

I have 2 Models(Article & Material) which are connected with a has_and_belongs_to_many assication

When i want to add a material to an article in the rails console i get this error:

Code:
article.materials = material_i_want_to_set

Error:

ActiveRecord::StatementInvalid: Fb::Error: The insert failed because a column definition includes validation constraints.
validation error for column ID, value "*** null ***"
: INSERT INTO "ARTICLES_MATERIALS" ("ARTICLE_ID", "MATERIAL_ID") VALUES (1, 1)

is this a bug?

thanks for your help


Reply to this email directly or view it on GitHub.

Thanks for the quick answer, it solved the problem.