@zfjoy520 是无序的,只有拥有 4,5,6 都符合!
@zfjoy520 你误会了!我不是要交集!我的意图是:几个商品,同时拥有 category_ids:["6","9","3"]!现在传入参数 category=6-3-9,然后把他转换成 array,传入 conditions,然后进行搜索!
@ChanceDoor {:node_id=>"1", :category_ids=>["9", "3", "6"]}这是 conditions!
这是 product,category_ids: ["6", "9", "3"]
#<Product _id: 3, _type: nil, created_at: 2013-04-27 01:37:21 UTC, updated_at: 2013-04-28 03:38:38 UTC, liked_user_ids: [], likes_count: 0, name: "干爽网面", howmany: nil, price: 0, exprice: 0, inprice: 0, size: "", use: nil, feature: "", inventory: 0, sales: 0, cover: 0, selling: true, barcode: "12121121212", special_offer: false, node_id: 1, manufacturer_id: 6, category_ids: ["6", "9", "3"], identifier: "", smell: "">
params[:product][:category_ids] = params[:product][:category_ids].map{|i| i.to_i}
logger.info(params[:product][:category_ids])
在 create 转换了为 i,但是保存到数据库还是 s,category_ids: ["5", "8", "3"]
conditions.merge!(:category_ids => params[:category].split("-").map{|i| i.to_s}) unless params[:category].blank?
logger.info(params[:category].split("-")) unless params[:category].blank?
logger.info(params[:category].split("-").map{|i| i.to_s}) unless params[:category].blank?
@products = Product.all(conditions).paginate(:page => params[:page], :per_page => 10)
而在搜索的时候转换,也没用!我用 logger.info 输出,不转换已经是 ["5", "8", "3"] 了,但是执行数据库搜索的时候,就会变成 [5, 8, 3]!
@Rei 因为是多对多,所以在 product 的表单里用 checkbox,他自动保存为字符
<%= check_box_tag "product[category_ids][]", category.id, @product.categories.map(&:id).include?(category.id) %>
@Rei 这样转换挺麻烦的?有办法在保存 product 数据时把它转换成整型保存吗?或者其他好办法?
@Rei 悲催!我看看!
@Teddy @lionzixuanyuan @Rei 谢谢!
MOPED: 127.0.0.1:27017 COMMAND database=meiyuewuyou_development command={:count=>:products, :query=>{"category_ids"=>{"$all"=>[9, 2, 6]}}} (0.4029ms)
=> #<Product _id: 3, _type: nil, created_at: 2013-04-27 01:37:21 UTC, updated_at: 2013-04-27 05:30:24 UTC, liked_user_ids: [], likes_count: 0, name: "干爽网面", howmany: nil, price: 0, exprice: 0, inprice: 0, size: "", use: nil, feature: "", inventory: 0, sales: 0, cover: 0, selling: true, barcode: "12121121212", special_offer: false, node_id: 1, manufacturer_id: 6, category_ids: ["2", "6", "9"], identifier: "", smell: "">
但是搜索没结果,是不是category_ids有顺序限制?
@Teddy 要自己写语句?
@lukefan 多对多下,如果 params[:tag_id] 是一个 id 数组呢?就是 [1,2,3] 查询出同时有这个的 article!
@1272729223 有联系方式?
@1272729223 得闲试试!前端高手,膜拜!
@ywencn 这个不是 mongoid 的!
@HungYuHei 谢谢,用 atomic 可以解决!
@sandy_xu 我的情况和他的不同!
class Picture
belongs_to :imageable, :polymorphic => true
end
class Deal
has_many :pictures, :as => :imageable, :dependent => :destroy
end
class SanitaryTowel
has_many :pictures, :as => :imageable, :dependent => :destroy
end
MOPED: 127.0.0.1:27017 QUERY database=meiyuewuyou_development collection=pictures selector={"imageable_id"=>213, "imageable_type"=>"SanitaryTowel", "imageable_field"=>{"$in"=>[:pictures, nil]}} flags=[:slave_ok] limit=0 skip=0 fields=nil (0.4086ms)
其中一条,但是没返回错误! 情况是,执行了,但是没保存进数据库!
好像是 p.update_attributes 不能保存!
@jasl 是开发环境
修改app/assets/javascripts/ueditor_config.js.erb里面的 toolbar,没效果的?
好的,谢谢! @ywencn 哈哈,如果没提醒,忽然忽略了就不好了