2

I take naming seriously because it even appears to the user in many places by default.

I would like to create a model named Group, which refers to something similar to Facebook groups.

Because group is very common I hoped that it was possible to use it as other common words (e.g. date), but... it is a reserved word in SQL and it is also an ActiveRecord method (i.e. Model.group(*args)).

I really cannot find a valid (and generic as I need) synonym: how should I behave in this case? Is there any convention or any common replacement for the word "group"?

4

2 に答える 2

1

パーティーに遅れましたが、同僚がこれを送ってきたので、訂正しなければなりませんでした。

解決策はあなたの識別子を引用することです。それなら問題ありません。Mysql では、バッククォート (`) で引用します。

MariaDB [some_db]> create view `group` as (select 1 as one);

MariaDB [some_db]> select * from `group`;
+-----+
| one |
+-----+
|   1 |
+-----+

Postgresql では、代わりに通常の二重引用符 (") を使用する必要がありselect * from "group";ます。MSSQL では、角括弧 ([]) を使用しますselect * from [group];

SQL には多くの予約語があり、新しい語が追加される場合があります。識別子が空いていることが確実でない限り、常に識別子を引用してください。

Active Recordは、デフォルトですべての識別子を引用する必要があります。場合によっては忘れる場合、それはバグである可能性があります。

于 2015-06-25T15:25:06.850 に答える