我有两个模型加入了has_many:通过关系:
class Publication < ActiveRecord::Base
has_many :publication_contributors
has_many :contributors, :through => :publication_contributors
end
class Contributor < ActiveRecord::Base
has_many :publication_contributors
has_many :publications, :through => :publication_contributors
end
class PublicationContributor < ActiveRecord::Base
belongs_to :publication
belongs_to :contributor
end
Run Code Online (Sandbox Code Playgroud)
(关于我的PublicationContributor模型的一些不寻常和重要的是它不仅仅有一对数据库ID,它还有一个名为contributor_type的字符串属性.这个字符串可能包含诸如"Author"或"Translator"或"Publisher"之类的角色.我不相信这是问题,但解决方案仍然必须考虑到它.)
我想找一个具有特定贡献者的出版物,如下所示:
Publication
.joins(:publication_contributors => :contributor)
.where(:publication_contributors =>
{:contributor_type => "Author",
:contributor => {:name => params[:authors]}})
Run Code Online (Sandbox Code Playgroud)
一切正常,直到我进入嵌套:贡献者,此时SQL溅出:
Mysql2::Error: Unknown column 'publication_contributors.contributor' in 'where clause'
Run Code Online (Sandbox Code Playgroud)
它不是在寻找publication_contributors.contributor_id,而是在寻找不存在的publication_contributors.contributor.我在代码中做错了吗?我找不到像这样具有深层嵌套关联的where子句的任何其他示例.也许它甚至不可能?
更新:
生成的SQL
?[1m?[35mPublication Load (0.0ms)?[0m SELECT `publications`.* FROM `publicati
ons` INNER JOIN `publication_contributors` ON `publication_contributors`.`public
ation_id` = `publications`.`id` INNER JOIN `contributors` …Run Code Online (Sandbox Code Playgroud) 我们在罗盘中具有出色的不透明度和过渡效果,但如何在不透明度上进行过渡?
@include single-transition(opacity, 1s);
Run Code Online (Sandbox Code Playgroud)
上面的行创建了一个不透明度的过渡,但没有创建-moz-opacity,-khtml-opacity,更不用说奇怪的IE语法......