简体   繁体   English

在rails关联的ruby中未定义的方法`where'

[英]undefined method `where' in ruby on rails association

我有两个表table1和table2与has_many belongs_to关系(table1有很多table2,table2属于table1)我写的值就像table2.table1.where(.....)但我有以下错误

NoMethodError: undefined method `where' for #<table1:0xc59764c> 

If table2 belongs to table1 , then calling table2.table1 will give you a single object of type table1 . 如果table2属于table1 ,那么调用table2.table1会给你一个table1类型的对象。 You can't call where on a single object (nor does it make sense to do so), only on a table or relation. 你不能调用where一个对象(也没有意义的,这样做的),只在一个表或关系。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM