Ruby China
  • Topics
  • 招聘
  • Wiki
  • Gems
  • Sign Up
  • Sign In
stephen
@stephen
VIP
NO. 445 / 2011-12-11

广东云浮新兴
249 Topics / 677 Replies
6 Followers
1 Following
173 Favorites
No GitHub.
  • Overview
  • Topics
  • Replies
  • Favorites
  • Following
  • Followers
  • 关于多对多关联的一个查询问题! at April 28, 2013

    @ChanceDoor 我就是不知道应该怎么写,你的意思是把参数的数组,循环搜索? @zfjoy520 是啊,就是这个功能!

  • 关于多对多关联的一个查询问题! at April 28, 2013

    @zfjoy520 恩,商品可能拥有更多 categories,例如 [3,7,12,6,8,9]! 顾客可能要筛选,[6,3,9],所以要搜索出 products 中拥有 [6,3,9]categories 的 products,返回给顾客,product 和 category 是多对多的关联

  • 关于多对多关联的一个查询问题! at April 28, 2013

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

  • 关于多对多关联的一个查询问题! at April 28, 2013

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

  • 关于多对多关联的一个查询问题! at April 28, 2013

    @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 April 28, 2013

    @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 April 28, 2013

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

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

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

  • 关于多对多关联的一个查询问题! at April 28, 2013

    @Rei 悲催!我看看!

  • 关于多对多关联的一个查询问题! at April 28, 2013

    @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 April 28, 2013

    @Teddy 要自己写语句?

  • Mongoid 怎样做关联查询? at April 27, 2013

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

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

    @1272729223 有联系方式?

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

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

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

    @ywencn 这个不是 mongoid 的!

  • mongoid 由 has_many 改为 polymorphic,应该要怎么做? at April 18, 2013

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

  • mongoid 由 has_many 改为 polymorphic,应该要怎么做? at April 18, 2013

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

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

    @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 April 17, 2013

    好像是 p.update_attributes 不能保存!

  • 新写的 ueditor rails integration at April 17, 2013

    @jasl 是开发环境

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