Ruby China
  • 社区
  • 招聘
  • Wiki
  • 酷站
  • Gems
  • 注册
  • 登录
stephen
@stephen
高级会员
第 445 位会员 / 2011-12-11

广东云浮新兴
249 篇帖子 / 675 条回帖
6 关注者
1 正在关注
173 收藏
未设置 GitHub 信息。
  • 概况
  • 话题
  • 回帖
  • 收藏
  • 正在关注
  • 关注者
  • 关于多对多关联的一个查询问题! at 2013年04月28日

    @zfjoy520 是无序的,只有拥有 4,5,6 都符合!

  • 关于多对多关联的一个查询问题! at 2013年04月28日

    @zfjoy520 你误会了!我不是要交集!我的意图是:几个商品,同时拥有 category_ids:["6","9","3"]!现在传入参数 category=6-3-9,然后把他转换成 array,传入 conditions,然后进行搜索!

  • 关于多对多关联的一个查询问题! at 2013年04月28日

    @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: "">
    
  • 关于多对多关联的一个查询问题! at 2013年04月28日

    @Rei

    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]!

  • 关于多对多关联的一个查询问题! at 2013年04月28日

    @Rei 因为是多对多,所以在 product 的表单里用 checkbox,他自动保存为字符

    <%= check_box_tag "product[category_ids][]", category.id, @product.categories.map(&:id).include?(category.id) %>
    
  • 关于多对多关联的一个查询问题! at 2013年04月28日

    @Rei 这样转换挺麻烦的?有办法在保存 product 数据时把它转换成整型保存吗?或者其他好办法?

  • 关于多对多关联的一个查询问题! at 2013年04月28日

    @Rei 悲催!我看看!

  • 关于多对多关联的一个查询问题! at 2013年04月28日

    @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有顺序限制?

  • 关于多对多关联的一个查询问题! at 2013年04月28日

    @Teddy 要自己写语句?

  • Mongoid 怎样做关联查询? at 2013年04月27日

    @lukefan 多对多下,如果 params[:tag_id] 是一个 id 数组呢?就是 [1,2,3] 查询出同时有这个的 article!

  • 父 div 设置了 position:relative,子类高度变化,父 div 不跟着变化,如何解决 at 2013年04月27日

    @1272729223 有联系方式?

  • 父 div 设置了 position:relative,子类高度变化,父 div 不跟着变化,如何解决 at 2013年04月27日

    @1272729223 得闲试试!前端高手,膜拜!

  • 淘宝,京东等商品多级分类较好的实现方法! at 2013年04月21日

    @ywencn 这个不是 mongoid 的!

  • mongoid 由 has_many 改为 polymorphic,应该要怎么做? at 2013年04月18日

    @HungYuHei 谢谢,用 atomic 可以解决!

  • mongoid 由 has_many 改为 polymorphic,应该要怎么做? at 2013年04月18日

    @sandy_xu 我的情况和他的不同!

  • mongoid 由 has_many 改为 polymorphic,应该要怎么做? at 2013年04月17日
    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
    
  • mongoid 由 has_many 改为 polymorphic,应该要怎么做? at 2013年04月17日

    @huacnlee

    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)
    

    其中一条,但是没返回错误! 情况是,执行了,但是没保存进数据库!

  • mongoid 由 has_many 改为 polymorphic,应该要怎么做? at 2013年04月17日

    好像是 p.update_attributes 不能保存!

  • 新写的 ueditor rails integration at 2013年04月17日

    @jasl 是开发环境

  • 新写的 ueditor rails integration at 2013年04月17日

    修改app/assets/javascripts/ueditor_config.js.erb里面的 toolbar,没效果的?

  • 一个电子商务网站,有顾客落订单后,如何在后台提醒? at 2013年04月03日

    好的,谢谢! @ywencn 哈哈,如果没提醒,忽然忽略了就不好了

  • 上一页
  • 1
  • 2
  • …
  • 10
  • 11
  • 12
  • 13
  • 14
  • …
  • 21
  • 22
  • 下一页
关于 / RubyConf / Ruby 镜像 / RubyGems 镜像 / 活跃会员 / 组织 / API / 贡献者
由众多爱好者共同维护的 Ruby 中文社区,本站使用 Homeland 构建,并采用 Docker 部署。
服务器由 赞助 CDN 由 赞助
iOS 客户端 / Android 客户端 简体中文 / English