activerecord

    1熱度

    1回答

    我在查詢一個activerecord模型枚舉並在where方法中使用like運算符,它只是不起作用。是否有一些技巧可以讓我以這種方式查詢枚舉?在常規欄目上正常工作。它在控制檯中。 普通字符串列(標題)以下 irb(main):092:0> Proposal.select(:id,:department,:status).where('title like "test%"') Proposal L

    1熱度

    2回答

    這是我的代碼 class CreatePosts < ActiveRecord::Migration[5.1] def change create_table :posts, id: :uuid do |t| t.string :name t.references :user, type: :uuid t.references :user,

    0熱度

    1回答

    我使用Ruby on Rails ver 5和MySQL創建Web應用程序。 該應用程序有兩個表categories和posts,其中一個categories有多個帖子(Category has_many :posts和Post belongs_to :category)。表結構如下所示。 類別型號 ID:整數 名稱:VARCHAR 郵政型號 ID:整數 CATEGORY_ID:整數 標題:VAR

    0熱度

    2回答

    我需要顯示來自具有活動訂閱的用戶的帖子。 模型/ user.rb has_one :profile, dependent: :destroy has_many :posts, dependent: :destroy 模型/ profile.rb - > suscription belongs_to :user, dependent: :destroy scope :active, -> (

    0熱度

    2回答

    我有一個Recipe模型和一個Ingredient模型。他們都配方和成分has_many :recipe_ingredients和配方has_many :ingredients, through: recipe_ingredients和配料has_many :recipes, through: recipe_ingredients和RecipeIngredient belongs_to。來自rec

    0熱度

    1回答

    我在我的網站上有一個頁面,它允許人們根據多個標準過濾汽車。這些標準通過參數傳遞。 我想添加一個新的標準,但模型中的邏輯是這樣的一種方法。我無法將其添加到我的控制器篩選邏輯中,因爲它都基於活動記錄查詢和可鏈接部分。 如何將以下方法轉換爲與我的過濾器邏輯中的查詢和鏈相兼容的東西? 方法: def self.new_cars_in_year(year) new_cars = []

    0熱度

    1回答

    我需要使用阿雷爾與 SELECT c2.user_id, MAX(c2.created_at) as max_created_at FROM comments AS c2 GROUP BY c2.user_id 被用作一個大的查詢子查詢的形式 SELECT * FROM comments INNER JOIN (...subquery...) s1 ON comments.user_

    0熱度

    1回答

    如何讓sql只有條件? Lead.where(status: 1).to_sql SELECT `leads`.* FROM `leads` WHERE `leads`.`status` = 1 我只需要條件的SQL。即, leads.`status` = 1 此外我有默認範圍。從我只需要該範圍爲sql

    0熱度

    1回答

    我正在使用globalize/globalize添加模型翻譯。 我有ru, en語言環境並想從對象中刪除en語言環境,我該如何刪除? 試圖以這種方式刪除,但它會刪除ru,en locales中的所有對象。 Country.with_translations(:en).find(1).destroy

    1熱度

    1回答

    我試圖映射在一個特定的數據結構中的AR關係(被渲染JSON),我不能讓它工作,由於某種原因,關係總是零 Client.includes(:fixed_odds_account, person: [:phones, :emails]).map do |client| { id: client.id, uri: client.uri, updated_at: c