首页
\
问答
\
继续获取ActiveRecord :: AssociationTypeMismatch(Keep getting ActiveRecord::AssociationTypeMismatch)
继续获取ActiveRecord :: AssociationTypeMismatch(Keep getting ActiveRecord::AssociationTypeMismatch)
我一直在努力解决这个问题好几天。 我一直收到错误:
ActiveRecord::AssociationTypeMismatch in SatellitesController#create Satellite(#70098878574220) expected, got String(#70098849353340)
我看过这个网站,但似乎没有任何帮助。 这是我到目前为止在我的代码中所拥有的:
在我的new.html.erb文件中:
<%= form_for( @satellite ) do |f| %> <div class="field"> <%= f.label :parent_id %></br> <%= f.select( :parent_id, Satellite.all.collect { |s| [ s.name, s.id ] }, { :include_blank => '-select-' } ) %> </div>
这就是我正在使用的关联:
class Satellite < ActiveRecord::Base validates :name, :presence => true, :uniqueness => true has_many :satellites, class_name: 'Satellite', foreign_key: 'parent_id' belongs_to :parent_id, class_name: 'Satellite', foreign_key: 'parent_id' end
任何帮助将不胜感激!
I have been working on fixing this problem for days. I keep getting the error:
ActiveRecord::AssociationTypeMismatch in SatellitesController#create Satellite(#70098878574220) expected, got String(#70098849353340)
I have looked all over this site but nothing seems to help. This is what I have in my code so far:
In my new.html.erb file:
<%= form_for( @satellite ) do |f| %> <div class="field"> <%= f.label :parent_id %></br> <%= f.select( :parent_id, Satellite.all.collect { |s| [ s.name, s.id ] }, { :include_blank => '-select-' } ) %> </div>
And this is the association I am using:
class Satellite < ActiveRecord::Base validates :name, :presence => true, :uniqueness => true has_many :satellites, class_name: 'Satellite', foreign_key: 'parent_id' belongs_to :parent_id, class_name: 'Satellite', foreign_key: 'parent_id' end
Any help would be GREATLY appreciated!
原文:https://stackoverflow.com/questions/15457318
更新时间:2024-02-03 17:02
最满意答案
json_group_array()
从它的元素构造一个数组; 从数组中提取值,请使用json_each()
:SELECT tag, count(*) FROM (SELECT j.value AS tag FROM Kittens CROSS JOIN json_each(Kittens.tags) AS j) GROUP BY tag;
json_group_array()
constructs an array from its elements; to extract values from an array, usejson_each()
:SELECT tag, count(*) FROM (SELECT j.value AS tag FROM Kittens CROSS JOIN json_each(Kittens.tags) AS j) GROUP BY tag;
相关问答
更多-
SQLite3记录操作(SQLite3 record manipulation)[2022-06-02]
要调用fetchone方法,您必须使用括号: if c.fetchone() is not None: 如果你不把fetchone()的返回值赋给一个变量,它就会丢失。 直接在光标上迭代将是一个更好的主意: for row in c: print('value in first column: ', row[0]) break else: print('not found') 而且你应该只选择一列,这使得访问它的价值更容易: c.execute('SELECT usergroup ... -
找到了很好的解决方案 Persist与AppJS完美配合,并且具有出色的非阻塞sqlite3驱动程序。 以防万一其他人在想 Found a great solution. Persist works perfectly with AppJS, and has a great non-blocking sqlite3 driver. Just in case anyone else was wondering
-
如果您需要精确的准确度,请勿使用浮子。 请尝试使用小数。 Don't use a float if you need precise accuracy. Try a decimal instead.
-
json_group_array()从它的元素构造一个数组; 从数组中提取值,请使用json_each() : SELECT tag, count(*) FROM (SELECT j.value AS tag FROM Kittens CROSS JOIN json_each(Kittens.tags) AS j) GROUP BY tag; json_group_array() constructs an array from its elements; to extract v ...
-
sqlite3 with python:在提交之前存储的数据在哪里?(sqlite3 with python: where is data stored before commit?)[2022-02-19]
SQLite在临时回滚日志文件中复制未修改的数据页,并将更改应用于这些相同页的内存副本。 当您进行足够的更改以使内存成为问题时,更改将刷新到原始数据库 。 回滚日志用于回滚未完成的事务。 不同数据库如何处理回滚日志在很大程度上取决于数据库实现。 符合ACID标准的数据库必须在某处存储未提交的事务数据,并且磁盘支持的日志是显而易见的选择。 SQLite文档包含有关如何实现事务的详尽说明 。 SQLite copies unmodified pages of data in a temporary rollba ... -
这是一个使用itemgetter和groupby汇集在一起的例子: >>> from operator import itemgetter >>> from itertools import groupby >>> sourcelist = [['300', '0', '1', '798', '53928', '283'], ... ['300', '0', '2', '210', '36160', '207'], ... ['300', '0', '3' ...
-
SQLite3查询执行问题(SQLite3 query executio issue)[2023-11-17]
您需要导航结果: while ($row = $results->fetchArray()) { var_dump($row); } 建议:阅读PHP手册,它非常有用....:xD You need navigate results: while ($row = $results->fetchArray()) { var_dump($row); } Advice: Read PHP Manual, it's very useful.... :xD -
将字典插入sqlite3(Inserting dictionary into sqlite3)[2023-12-03]
这是一个简单的数据库设计问题。 我建议: CREATE TABLE country_clicks ( id INTEGER PRIMARY KEY, country STRING, accessed_from STRING, clicks INTEGER ); CREATE UNIQUE INDEX country_clicks_idx ON country_clicks(country, accessed_from); 通常,我会推荐country和accessible_from ... -
你已经通过电子重建运行sqlite3了吗? $ electron-rebuild -f -w sqlite3 要么 $ npm rebuild Have you already run sqlite3 through electron-rebuild? $ electron-rebuild -f -w sqlite3 or $ npm rebuild
-
首先是Python位。 假设my_arr是某种二维数组,并且.tolist()生成列表列表,是的,有一种方法可以将元素添加到列表中的每一行: result = [[a]+b for a,b in zip(TableNameList, my_arr.tolist()] 二,SQL位。 不,你不能用? 指定表名。 表名必须字面上存在于SQL语句中。 我能为您提供的最好的方法是多次运行curssor.execute : for table, values in zip(TableNameList, my_arr ...