Should AR where support `db_name.table_name.column_name` to key of hash?
issueの本文開始。
ActiveRecordのwhereは ハッシュのキー「 db_name.table_name.column_name
」をサポートするべきです。
Now db_name.table_name.column_name is not supported as key of hash
今、db_name.table_name.column_name
はハッシューのキーとしてサポートしていない。
Rails 4.2.3 with mysql2
[1] pry(main)> User.where("id" => 1).to_sql => "SELECT
users
.* FROMusers
WHEREusers
.id
= 1"[2] pry(main)> User.where("users.id" => 1).to_sql => "SELECT
users
.* FROMusers
WHEREusers
.id
= 1"[3] pry(main)> User.where("db.users.id" => 1).to_sql => "SELECT
users
.* FROMusers
WHEREdb
.users.id
= 1"[3] is invalid SQL because
db
.users.id
Rails 5.0.0 (07d6e1dc1fc78abaf46f9a73ded0b370ba489f6c) with mysql2
[1] pry(main)> User.where("id" => 1).to_sql => "SELECT
users
.* FROMusers
WHEREusers
.id
= 1"[2] pry(main)> User.where("users.id" => 1).to_sql => "SELECT
users
.* FROMusers
WHEREusers
.id
= 1"[3] pry(main)> User.where("db.users.id" => 1).to_sql => "SELECT
users
.* FROMusers
WHEREdb
.users
= 1"!!!! column name is lost!
Sure when we add database_name as AR.table_name these method create valid SQL
ActiveRecord.table_nameとしてdatabaseを追加すると正しいSQLを作ること確かめますね。
class User < ActiveRecord::Base self.table_name = "rails_spike_development.users" end
Rails 4.2.3 with mysql2
[1] pry(main)> User.where("id" => 1).to_sql => "SELECT
rails_spike_development
.users
.* FROMrails_spike_development
.users
WHERErails_spike_development
.users
.id
= 1"Rails 5.0.0 (07d6e1dc1fc78abaf46f9a73ded0b370ba489f6c) with mysql2
[1] pry(main)> User.where("id" => 1).to_sql => "SELECT
rails_spike_development
.users
.* FROMrails_spike_development
.users
WHERErails_spike_development
.users
.id
= 1"Both of them work correctly
But some gems use table_name as key
しかし、いくつかのgemはkeyとしてtable_nameを使う。
https://github.com/mbleigh/acts-as-taggable-on/blob/master/lib/acts_as_taggable_on/taggable/core.rb#L319 https://github.com/aasm/aasm/blob/master/lib/aasm/persistence/base.rb#L61
Should AR where support db_name.table_name.column_name to key of hash?
AR.whereは ハッシュのキーとしてdb_name.table_name.column_name
をサポートするべきではありませんか?
レスの1つ目
@yui-knk did you find the commit that changed how this works? Maybe there's some insight there why this change happened in the first place.
あなたは、この働きに変更したコミットを見つけましたか?まー僕は発端はいくつか思い当たるけど。
レス2つ目
@senny I found out this commit change behavior.
私は変更の振る舞いのコミットを見つけた。 [...]
レス3つ目
We should definitely continue to make sure that this continues to generate invalid SQL and not silently do the wrong thing. That part should be easy to implement.
In terms of actually supporting this, I'm not a fan of allowing the db name in the string (or the dot notation in general for calls to where). One thing I am hoping to do is have where more specifically target the association, rather than the table, in order to gain more information about the model we're joining on. Once that lands, we could allow specifying database_name on the model class. However, I'd want to see a concrete use case for that, since if you statically know the database that the table lives on, I'm not sure why you'd want it on separate DBs to begin with.
The sharding use case is more complex (too much for me to get in depth on right now), but it is something I want to tackle (not so much to say "this is how you shard in Rails", but more to add the hooks required for you to do it without monkey patching). It's something I'll be working on in the near future.
私たちは、誤ったSQLを作成し、静かに誤りは続けずに間違いなく確認し続けるべき。 [...]
このdb_nameをハッシュのキーに入れたいということは了解してくれたみたいだけど、いつ取り込まれるんだろう。 目が離せません。
Should AR where support `db_name.table_name.column_name` to key of hash? · Issue #21326 · rails/rails · GitHub Remove @klass.table_name from scope conditions key by yui-knk · Pull Request #244 · aasm/aasm · GitHub
DNSの理解を少し深めた
/proc を探検する - いますぐ実践! Linuxシステム管理 / Vol.023
名前解決の理解がかなり曖昧だった。
NSサーバを適当に登録して、aレコードやcnameレコードを適当に投稿してWEBサーバのバーチャルホストを設定するだけで大抵動くので曖昧のままでご飯を食べれてた。
今回、ブラウザが再帰的に権威サーバへ再帰的に問合せしている手順をdigコマンドを使って再現した。 だがまだ理解が微妙だ。
今回はgoogle.comの名前解決をしてみた。
com を知っているnsサーバを問い合わせる
$ dig com ns ;; ANSWER SECTION: com. 11257 IN NS m.gtld-servers.net. com. 11257 IN NS j.gtld-servers.net. com. 11257 IN NS e.gtld-servers.net. com. 11257 IN NS c.gtld-servers.net. com. 11257 IN NS l.gtld-servers.net. com. 11257 IN NS k.gtld-servers.net. com. 11257 IN NS g.gtld-servers.net. com. 11257 IN NS i.gtld-servers.net. com. 11257 IN NS a.gtld-servers.net. com. 11257 IN NS h.gtld-servers.net. com. 11257 IN NS d.gtld-servers.net. com. 11257 IN NS f.gtld-servers.net. com. 11257 IN NS b.gtld-servers.net.
答えがたくさん帰ってきた。com を知っているサーバは*.gtld-servers.netだ。
次は *.gtld-servers.netのnsに対して、google.com のnsを問い合わせる。
google.com の ns サーバを問い合わせる
$ dig @a.gtld-servers.net google.com ns ;; AUTHORITY SECTION: google.com. 172800 IN NS ns2.google.com. google.com. 172800 IN NS ns1.google.com. google.com. 172800 IN NS ns3.google.com. google.com. 172800 IN NS ns4.google.com.
google.com を登録しているnsサーバは ns2.google.com あたりということがわかった。 次はaレコードをns2.google.comに問い合わせる。
$ dig @ns2.google.com google.com a ;; ANSWER SECTION: google.com. 300 IN A 173.194.117.199 google.com. 300 IN A 173.194.117.194 google.com. 300 IN A 173.194.117.192 google.com. 300 IN A 173.194.117.197 google.com. 300 IN A 173.194.117.201 google.com. 300 IN A 173.194.117.200 google.com. 300 IN A 173.194.117.193 google.com. 300 IN A 173.194.117.206 google.com. 300 IN A 173.194.117.196 google.com. 300 IN A 173.194.117.198 google.com. 300 IN A 173.194.117.195
google.com を手で問い合わせた。
権威サーバというのは、com や google.com のnsを知っているサーバのことを指すらしい。 ns2.google.com は 権威サーバというのかな。
ゾーンファイルを持っているのは、ns2.google.com だと思う。
うーーーーーん。なんか微妙に理解ができていない。 nsレコードとはなんなんだ....。
telnet 使った
telnet でメールのチェックをする - いますぐ実践! Linuxシステム管理 / Vol.020
telnetでsmtpと話をした。 HELOしてRCPTしたら拒絶された。それとVRFYとEXPNした。 VRFYはユーザがいるか返してくれる。EXPNは転送先を返してくれるはずなんだけどnot found comanndとなった。 セキュリティの観点からそうなったのかな(´・_・`)
たまにメールサーバは不調なので調査をしてください、って依頼が入るのでこれでバッチシです。
SSHログインされたタイミングで通知する・ログをとる
WWW を使ってログをとる - いますぐ実践! Linuxシステム管理 / Vol.011
SSH で遠隔ログインした時にメールで通知する - いますぐ実践! Linuxシステム管理 / Vol.010
をやりました。
sshdがキックされると~/.ssh/rc が実行されるようで、そこにmailコマンドを書いたり、WEBサーバにGETを投げたりした。 また、課題ではprintenvの内容をメールしたり、scpではrcがキックされないようにしたりした。 sshすると環境変数のTERMにセットされるの知らなかった。
環境変数TERMについて調べると、接続端末によって特殊文字の定義が異なるため、端末と特殊文字を紐付けたデータベースがあり、 Vimやshellなどのアプリケーションは、そのデータベースから適切な出力をしているとのこと。
なるほどなー。
Rails Documentation. Getting Started Tutorial not working. 1
RailsドキュメントのGetting Started が動かない。
Rails Documentation. Getting Started Tutorial not working. · Issue #19330 · rails/rails · GitHub
本文
あなたがgetting startedチュートリアルをフォローしているのなら、セクション5.2の終わりに気づくだろう。 formの入力やsubmitボタンをクリックするとき、チュートリアルに従っていないルーティングエラーが起きる。 わたしはこの修正方法を知らない。解決するためには何ができますか?
返信
もし、あなたがあなたのformをペーストしたらそれは助けになっただろう。そう、私たちはそれとガイドを比較できる。 (そのエラーの)は原因は、ガイドのurlにある、formは不正確であり、あなたはこのように変えるべきだ。 私には正しく見えるので今の所はこれを閉じるよ。
うーーーーーーーーーーーーーーん。なんか意図がわからん。
Weird behavior of POST, PUT and DELETE in Mozilla Firefox
Weird behavior of POST, PUT and DELETE in Mozilla Firefox · Issue #19278 · rails/rails · GitHub
FireFoxでPOST, PUT, DELETEをすると変な振る舞いをする
本文
Hi! I'm making forum https://github.com/vladzzag/rails-forum どうも、私はフォーラムサイトを作っている。そして、FirefoxでPOST, PUT, DELETEリクエストで何か問題が見つかった。1クリックにつき複数回それらのリクエストが送信された。スクリーンショットを見て。また、chromeでは問題がないことを気がついた。 FireFoxでそのバグについて教えてくれることはできますか? 私は英語のスキルが不完全でごめんなさい。
返信
私たちはあなたのバグを助けることやFireFoxをテストを助けることはできない。 QAサイトかメーリングリストで試してくれ。
返信(主)
わかった。link_toメソッドにDELETEメソッドと { data: :confirm } を追加すると1POSTリクエストの代わりに3リクエスト送られた。
とても奇妙だ....。
最近issuesを読んでいるとQAサイトみたいな使い方をしている人はよくいますねー。