作者:木目心磊_559 | 来源:互联网 | 2023-09-13 14:49
IhaveamodelnamedUser,Iamstoringahashtotheusermodelinattributeparams.Ihavedeclare
I have a model named User, I am storing a hash to the user model in attribute params. I have declared this column as store in my user model without any accessor,I am accessing it as @user.params
, while saving data to database it works quite fine. However, I have to retrieve data by certain criteria.
我有一个名为User的模型,我在属性参数中将哈希存储到用户模型。我已将此列声明为我的用户模型中的存储而没有任何访问者,我将其作为@ user.params访问,同时将数据保存到数据库它可以正常工作。但是,我必须按某些标准检索数据。
Say I have stored a user Object with params field as { checked: true } and Other by { checked: true }
假设我已将用户对象与params字段存储为{checked:true},其他用{checked:true}存储
Now I have to retrieve user having params: { checked: true}
现在我必须检索有params的用户:{checked:true}
The query I am using is:
我正在使用的查询是:
User.where(params: {"checked" => true});
This is Throwing Error as:
这是投掷错误:
INTERNAL ERROR!!! SQLite3::SQLException: no such column: params.checked: SELECT "users".* FROM "users" WHERE "params"."checked" = 't'
I searched a ton about comparing two store fields in database but have not found related stuff.
我搜索了很多关于比较数据库中的两个商店字段,但没有找到相关的东西。
Thanks In Advance
提前致谢
2 个解决方案