ActiveRecord IN clause
環境
$ rails -v Rails 5.1.2
基本形 where(カラム: [要素])
Model.where(id: [1,3,5])
enumのSymbolもそのままいける
Model.where(status: [:active, :inactive])
参考:
【SQL】今週の日曜日・今週の土曜日を求める
メモ:
CURRENT_DATE - interval (DAYOFWEEK(CURRENT_DATE) - 1) day AS THIS_SUNDAY
日曜日始まりとする。
今日の曜日インデックス(DAYOFWEEK(CURRENT_DATE)
)から日曜日の曜日インデックスを引くと、今日が日曜日から何日目かが分かる。
CURRENT_DATE + interval (7 - DAYOFWEEK(CURRENT_DATE)) day AS THIS_SATURDAY
土曜日の曜日インデックスから今日の曜日インデックスを引くと、土曜日は今日から何日目かが分かる。
もしかしたらそれ用の関数とか用意されてるのだろうか
Alpineでパッケージをインストールしようとしたらエラーがでたので解消する
メモ
ERROR: unsatisfiable constraints: py-pip (missing): required by: world[py-pip] ERROR: Service 'web' failed to build: The command '/bin/sh -c apk add py-pip' returned a non-zero code: 1
インストール可能なパッケージ一覧(インデックス)の更新オプションを付けると解消される (--update
)
apk add --update py-pip
Macでファイル内の文字列を再帰的に置換するコマンド
Re:dash SQLクエリ内で変数を使う方法
メモ。クエリが複数になるとエラーになるっぽい
SELECT id, (SELECT @date := huga) AS date, FROM hoge
Warning: Material-UI: The white color was not parsed correctly, because it has an unsupported format (color name or RGB %). This may cause issues in component rendering.
const muiTheme = getMuiTheme({ raisedButton: { textColor: 'white', color: purple900, } });
こんな感じにMaterial-UIの色を変えて遊んでたらエラーが出た:
Warning: Material-UI: The white color was not parsed correctly, because it has an unsupported format (color name or RGB %). This may cause issues in component rendering.
ヘックスコードに変えれば問題はない:
const muiTheme = getMuiTheme({ raisedButton: { textColor: '#ffffff', color: purple900, } });
Rails5 FactoryGirlでコールバックをスキップする方法
Rails4では使えたFoo.skip_callback(:create, :after, :bar)
がRails5では使えない。
ArgumentError: After create callback :do_something has not been defined
対策として、次のようにFGにおいてメソッドを上書きする:
class User < ActiveRecord::Base after_create :run_something end
FactoryGirl.define do factory :user do after(:build) do |user| class << user def run_something true end end end factory :user_with_run_something do after(:build) do |user| class << user def run_something super end end end end end end
コールバックメソッドの発火タイミングによって、after(:build)
も変更する必要がある
参考: