arel

    0熱度

    1回答

    所以在軌道,我有 class Organization < ActiveRecord::Base has_many :boxes class Box < ActiveRecord::Base has_many :items belongs_to :organization class Item < ActiveRecord::Base belongs_to :box 沒有增加對

    1熱度

    1回答

    我有以下型號 class Recipe < ActiveRecord::Base has_many :recipe_allergens has_many :allergens, through: :recipe_allergens end 我試圖找到所有不具有給定一組過敏原的食譜,所以我嘗試joins(:allergens).where.not(allergens: {

    1熱度

    3回答

    我有一個AREL查詢,我生成了很多痛苦。供參考(對不起): def self.summarize_user(user) c = Arel::Table.new(:categories) s = Arel::Table.new(:skills) cp = Arel::Table.new(:completions) query = c.project(c[:i

    3熱度

    2回答

    我有一個關於使用AND和OR合併幾個條件的問題,其中一個關於操作優先級。 所以,我需要生成以下SQL字符串傳遞給where方法: where("NOT ((assignments.to IS NOT NULL AND assignments.to < :start_date) OR assignments.from > :end_date)", start_date: date.at_beginn

    0熱度

    1回答

    我有一個Gallery該has_manyMediaItem S,其中的每一個has_oneVideo或Photo。 我目前使用下面的查詢: MediaItem.includes(gallery: {media_items: [:photo, :video]}).featured.rank(:position_in_featured) 但是鑑於媒體項目將永遠只能有一個Video或Photo,我總

    0熱度

    1回答

    在Rails應用程序中,我需要返回包含多列的ActiveRecord集合,但只有1列必須是唯一的。有一個默認範圍不是唯一值。 默認適用範圍 default_scope { order('executed_at DESC') } 當前的查詢,而獨特:條款。 Search.where(organization_id: @my_array_of_ids) .executed_after(

    1熱度

    1回答

    有沒有辦法使用ARel按字符串字段的大小選擇記錄?例如,如果我有一羣用戶,我可以選擇所有名字爲3個或更少字符的用戶嗎?我可以做一些像用繩子 User.where('LENGTH("users"."firstname") < 3') 我希望能夠做到像 User.where(User.arel_table[:firstname].length.lt(3)

    1熱度

    3回答

    我正在使用RAILS 4和MySQL 服務通過服務場所有很多地方。 我想創建一個AREL相當於下面的SQL查詢: SELECT DISTINCT services . * FROM services INNER JOIN (SELECT DISTINCT `services` . * FROM `services`

    3熱度

    1回答

    我稱之爲「move_to_end」我使用的find_by_sql如下調用Postgres的功能: def move_to_end self.class.find_by_sql ["select move_to_end(?)", id] end 我想更換一個AREL調用的find_by_sql聲明,但所有的例子,我發現要求arel與桌子一起工作。 有關如何完成此任何想法,將不勝感激。

    15熱度

    3回答

    如果有多個具有相同表格的聯接,則有些情況下ActiveRecord會設置別名表名稱。我陷入了這些連接包含範圍的情況(使用'合併')。 我有很多一對多的關係: 型號表名:users 二款表名:posts 加入表名:access_levels 一個帖子有許多用戶通過access_levels,反之亦然。 兩種,用戶模型和Post模型共享相同的關係: has_many :access_levels, -