Hard work by INTERNET

ベンチャーで働くひとりぼっちWEB開発者が頑張るブログ

ActiveRecord::Base#dup が動的属性を含めてくれない(does not include dynamic attributes) #34823

github.com

本文

rails4.2.xでは、 lib/active_record/core.rb#initialize_dup が正しく複製してくれるけれども、rails5.2ではpullするだけ MyModel._default_attributes によって、すでに複製したものを削除する。

Yes this still occurs on 5-2-stable. I've already included details on where the offending code is.. Right now we have resorted to manually handling duping because of the broken rails AR code.

rails5.2のステイブルではまだ起きている。問題のコードの場所は >>1にすでに含めています。 ActiveRecordのコードが壊れたことによって、私達は手動での複製処理に頼っています。

Since you know where the offending code is, what do you thing about opening a PR?

問題のコードをあなたは知っているので、プルリクエストを開くことについてどう思っていますか?

I can do that sometime next week.

来週なにかできるよ。

以降音沙汰なし。

railsのアンダースコアに変換するメソッドの戻り値がおかしいんけど

github.com String inflection method underscore giving wrong output #37163

質問

アンダースコアライズする文字列変換文字列のアウトプットがおかしいんだが?

Open up rails console and type - "ActLikeStar".underscore gives you 'act_like_star' which is correct.

rals consoleでこれを入力すると、"ActLikeStar".underscore 'act_like_star' になる。これは正しい。

Now Type - "AB".undescore . which gives you 'ab' which seems to be incorrect.

次は "AB".undescore .を入れると 'ab' になる。おかしい。 a_b のような出力を与えるべきだ。 It should give output like this 'a_b'

回答

これは期待通りの振る舞いです。頭字語の見た目がナイスになります。 あなたは他の変換例をもっと見ることができるよ。

github.com

回答2

先の人が回答したように想定した振る舞いです。 全角だけで表現している場合は、ほとんどのケースではアンダースコアを含めないことを期待している。

おわり

検索条件が空を返す時にどうしてSQLを発行してんの?

Why do it need to execute SQL when ActiveRecord query conditions is empty array? · Issue #35307 · rails/rails · GitHub

User.where(id: [])

というコードを実行すると SELECT COUNT(*) FROM users WHERE 1=0という空を返却するSQLを発行している。必要なくね?というissue。

本issueに書かれた内容を要約すると、 SQLselect ... where in ()というinの中身が空欄は不正なSQLになるから、エラーにならないように空結果を返すために1=0で検索しているけど、どうせ空配列を返すことはクエリする前から決まっているんだから内部でnoneメソッドを使えばいいのに。
まーでも、ここを最適化するよりもクエリをすることで実装がシンプルになるならこれでいいんじゃないの。

みたいな感じで、コミッターが登場することもなく答えのないままオープンになっている。

おしまい。

Remove unnecessary check.

github.com

issue 本文

railsアプリケーションは、デフォルトでapplictionオブジェクトをセットしている。 だから不要なチェックは削除する。

     def root
-      application && application.config.root
+      application.config.root
     end

返信

Not everything that has done require "rails" is a (booted) Rails application.

require 'rails' を実行するとrailsアプリケーション、というのは全部じゃない。

感想

どういうケースでrailsアプリケーションじゃないのにrequire 'rails'をしているんだろう。 誤訳している?

updated_attributeメソッドで 属性が変更されなかったならtrueを返す

github.com

issue本文

If the attribute is not changed, then update_attribute does not run SQL query, this effectively means that no change was made to the attribute.

属性が変更されなかったらupdate_attributeメソッドはSQLクエリを実行せず、実際には項目に変更はなかったことを意味する。

This change was made in 0fcd4cf to avoid a SQL call.

この変更は SQLコールを防ぐ ofcd4cf で作られた。

But the change resulted into nil being returned when there was no change in the attribute value.

しかし、この変更の結果は、属性の値に変更がないときにnilを返すことになる

This commit corrects the behavior to return true if there is no change in attribute value. This is same as previous behavior of Rails 4.2 plus benefit of no additional SQL call. Fixes #26593.

属性の値に変更がない場合、trueを返す動作のコミットは正しい。

This is same as previous behavior of Rails 4.2 plus benefit of no additional SQL call.

この修正は、rails4.2以前と動作が同じである。
(of が多くて単語の切れ目とplus benefit がどこに掛かっているのかわからず)

@tenderlove We should backport as well, as this behavior was originally changed on 5.0.

バックポーツするべきだ。この振る舞いは5.0で変更された。

There was a conflict with persistence_test.rb so this commit could not be cherry-picked directly to 5-0-stable. I fixed the conflict and opened #26603 for back porting.

persistence_test.rb でコンフリクトがあって、5-0-stableに直接チェリーピックができなかった。 私は、コンフリクトの解消と バックポーツのために #26603 をオープンした。

DateTime#blank? のメソッドをempty?を使うように修正する

github.com

issue本文

I think DateTime#blank? should be use Object#blank? method.

DateTime#blank? は Object#blank? を使うべきだと思う。

WDYT?(Why do you thihk?)

どう思う?

返事

Inheritance is only left to non-whitelisted classes. The method is overridden in a bunch of them for performance reasons.

継承はノンホワイトリストクラスだけに任せている。(よくわからない....。?)

そのメソッドはパフォーマンス上のため上書きされている。

感想

Object#blank? は遅いって聞きますよね。

ActiveRecord exec_query fail for nonselect requests

github.com

本文

non select クエリーを exec_query#ActiveRecordで実行すると失敗する。

ActiveRecord::Base.connection.exec_query( 'update orders set id=1 where id=1' )

これのようなnon select クエリーを実行。

NoMethodError: undefined method `fields' for nil:NilClass

(正しいSQLとは独立して)例外になって失敗する。

(クエリは常に適用され、期待通りフィールドは常に更新された。)

これがバグじゃないなら、ActiveRecord::Resultインスタンスと同じいくつかのSQLを実行する方法

どうやって、選んだレコードと空レコードを判別しながら同じ結果(ActiveRecord::Result)のSQLを実行をするのか。

返信

Please use the mailing list or StackOverflow for questions/help, where a wider community will be able to help you. We reserve the issues tracker for issues only.

メーリングリストかスタックオーバーフローを質問・助けの場のために使って、広いコミュニティがあなたを助けることができるでしょう。

私達は、イシュートラッカーを課題のためだけに確保しています。

感想

2つの助動詞を入れられないためbe able toとwillがでてきて「進研ゼミでやったところだ!」ってなった。