pluck

    -2熱度

    2回答

    我有一個叫做Record的模型,它屬於產品型號, price列類型是十六進制。 Rails已經將它轉換爲視圖中的字符串。但我想讓他們在我的控制檯查詢中。對於拔毛 示例代碼: Product.first.records.pluck(:price) 此查詢顯示在陣列爲十六進制的值。有一種叫做to_sentences的方法,但它對我的情況來說還不夠。 的問題是相同的collect方法: Produc

    1熱度

    1回答

    在控制器我用拔毛法從我的數據庫 @user1 = User.where(name: 'Alex').pluck(:id, :name).first @user2 = User.where(name: 'Alex').pluck(:id, :name) 得到ID,並將它命名返回數組 @user1 = `[3, 'Alex']` @user2 = [[3,'Alex'],[4, 'Alex']

    0熱度

    4回答

    我從Active Record採集中發現了一個奇怪的行爲。 我查詢 Friend.joins('INNER JOIN users ON friends.friend_id = users.id').where("user_id=? AND (status=? or status=?)", 4,"true","").pluck("users.first_name, users.last_name")

    0熱度

    1回答

    我試圖過濾一個具有多個條件的匹配記錄數組,並且似乎無法弄清楚,我嘗試了很多不同的東西,並搜索了一切,但沒有任何結果。 ..這裏是代碼: if @post.last_post? @recommendations = @course.recommendations_for_subscriber(subscriber, category, language).first(3) end 和

    1熱度

    2回答

    這是不可能的,因爲它是正確的,但現在我有一個像這樣 events = Event.as(:e).where("((e.date_start - {current_time})/{one_day_p}) < 1 ").users(:u, :rel).where("rel.reminded = {reminded_p}").params(reminded_p: false, one_day_p: on

    4熱度

    1回答

    如何我有一個巨大的表foo從中我需要摘下在某一個領域,Foo.who所有值。 陣列具有數百萬行的,但在who列只有幾千不同的值。 如果表當然是小我會簡單地使用Foo.pluck(:who) 如果我使用Foo.find_in_batches do |a_batch|每一組是富記錄的數組,而不是富記錄的ActiveRecord的集合,所以我不能使用.pluck()和AFAIK提取who列的唯一方法是通

    1熱度

    2回答

    第一次使用下劃線,我卡住了,找不到示例。 我的數據是: [{ "store_name": "Store 1", "franchisee_id": "id01", "dish_menu": "Breakfast", "dish_count": "17" }, { "store_name": "Store 1", "fr