activerecord_where_assoc:使ActiveRecord在关联上执行条件

时间:2021-01-30 21:46:18
【文件属性】:
文件名称:activerecord_where_assoc:使ActiveRecord在关联上执行条件
文件大小:425KB
文件格式:ZIP
更新时间:2021-01-30 21:46:18
ruby rails activerecord sql rails5 ActiveRecord哪里Assoc 使用此gem可以轻松地根据ActiveRecord(Rails)中记录的关联来进行条件。 (使用SQL的EXISTS运算符) # Find my_post's comments that were not made by an admin my_post . comments . where_assoc_not_exists ( :author , is_admin : true ) . where ( ... ) # Find every posts that have comments by an admin Post . where_assoc_exists ( [ :comments , :author ] , & :admins ) . where ( ... ) # Find my_user's posts that have at least 5 non-spam comments (not_spam is a scope on comments) my_user . posts . where_assoc_count ( 5

网友评论