开发者

rails 3 - belongs_to :uniqueness

I want do a one-to-one relationship, unique.

So I have in a model this association and validation开发者_如何学编程

belongs_to :bicycle validates :bicycle, :presence => true, :uniqueness => true

And give me this error:

ActiveRecord::StatementInvalid: SQLite3::SQLException: near "FROM": syntax error: SELECT FROM "transactions" WHERE ("transactions"."bicycle" IS NULL) AND ("transactions"."bicycle" IS NULL) LIMIT 1

I don't know why the query is not well constructed... It is a bug of rails3?


You should probably validate the attribute and not the association. The attribute in this case would be bicycle_id. So if you change it to:

validates :bicycle_id, :presence => true, :uniqueness => true

that should work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜