activerecord

    0热度

    1回答

    比方说,我有一些模型 class MyModel < ApplicationRecord scope :opened, -> { where(status: 'open') } scope :closed, -> { where(status: 'closed') } scope :colored, -> { where.not(color: nil) }

    0热度

    1回答

    我想将postgresql数据从json列移动到同一个表内的不同列。 我该如何有效地做到这一点?我的heroku控制台在10-20分钟后死亡,我有100,000多条记录需要更新。 Ticket.where(payment_type: nil).find_each(batch_size: 1000) do |ticket| ticket.update_attributes(payment_

    0热度

    2回答

    我需要一个控制器来传递符合特定范围的父项的子项记录。我希望这个范围在父记录上。 class Parent < ApplicationRecord has_many :children scope :not_blue, -> { where(blue:false) } scope :blue, -> { where(blue:true) } # Subj

    0热度

    2回答

    在我的应用程序中,员工用户创建患者记录。患者模型与保险模型具有HABTM关系,以记录患者所覆盖的保险。 员工用户创建属于患者的推荐请求。职员用户也属于大学,而大学又属于市场。例如,职员用户吉姆可能属于哈佛大学,而哈佛大学又属于波士顿市场。 临床医生用户直接属于市场。 临床医生用户每个人都有一个临床医师简介,他们的档案与保险模型有HABTM关系,以记录保险/临床医生接受的保险。 ClinicianP

    1热度

    2回答

    使用AND条件我现在有这三个表: create_table "cocktail_ingredients", force: :cascade do |t| t.integer "cocktail_id" t.integer "ingredient_id" t.datetime "created_at", null: false t.datetime "updated_at", null: f

    0热度

    1回答

    我有两个模型在Rails 5.1 class Category < ActiveRecord::Base has_and_belongs_to_many :sub_categories, join_table: "categories_join_table" end class SubCategory < ActiveRecord::Base has_and_belong

    0热度

    1回答

    我有这样的阵列由ActiveRecord的查询返回: SELECT id, value FROM table ORDER BY value DESC [1054, 86], [1062, 86], [1059, 84] 而且我已经创建了一个简单的阵列与第一阵列进行比较: array.sort_by! {| object | object.access_count}} .reverse 但是,

    0热度

    1回答

    当我创建类别配方的新对象时,没有数据被插入到方向模型表格中。 配方控制器: class RecipesController < ApplicationController before_action :find_recipe, only:[:show, :edit, :update, :destroy] def index @recipe = Recipe.all.

    0热度

    1回答

    我有两种模式:学校和地址。 Address has_many :schools School belongs_to :address t.bigint "address_id" 现在我需要在学校模型中构建范围,以便根据地址表中的城市发生情况对学校进行排序。所以,我需要以下结果: School_1 | City_most_popular School_2 |

    0热度

    1回答

    A transaction_record有许多workflows,并且每个workflow有许多milestones。其中一个milestones的标记current: true,我想从transaction_record到current_milestone去: class TransactionRecord < ApplicationRecord has_many :workflows