Noms réservés avec les modèles ActiveRecord

Je prends les noms très au sérieux, alors je pense assez aux bons noms pour mes modèles ActiveRecord. Cependant, je trouve souvent un nom et il y a un conflit avec un nom réservé, que ce soit dans la firebase database ou dans Ruby ou Rails. Noms de modèle ou de champ tels que set ou group . Parfois, le problème n’est pas évident non plus. Existe-t-il une liste de noms que nous ne pouvons pas utiliser dans nos noms de modèles et une liste de noms de champs?

Voici quelques ressources pour vous aider à démarrer:

  1. Rails mots réservés . Celui-ci semble être assez à jour, mis à jour en février 2010. Il va même au-delà des rails et répertorie certains conflits de noms courants avec SQL. mort
  2. Mots réservés dans les rails . Ici vit une application de heroku avec une table consultable de mots de rails réservés. Le contenu de celui-ci semble être géré par l’utilisateur, de sorte que toute personne disposant d’un compte peut append un nouveau mot.

Le type nom de colonne est également réservé et ne figure pas dans la liste des MyModel.methods !

The single-table inheritance mechanism failed to locate the subclass: 'f'. This error is raised because the column 'type' is reserved for storing the class in case of inheritance. Please rename this column if you didn't intend it to be used for storing the inheritance class or overwrite Project.inheritance_column to use another column for that information.

Est-ce que quelqu’un a de l’expérience avec des noms tels que category , class , transaction , group , etc.? Tout cela me vient à l’esprit lorsque je catégorise des données dans ma firebase database ….

Ouvrez une console de rails et un type MyModel.methods

Toutes les méthodes répertoriées sont des mots réservés.

Voici la liste de Rails 5.1.5 :

 ! != !~ <=> == === =~ [] []= __binding__ __callbacks __callbacks? __id__ __send__ _before_commit_callbacks _before_commit_without_transaction_enrollment_callbacks _commit_callbacks _commit_without_transaction_enrollment_callbacks _create_callbacks _destroy _destroy_callbacks _find_callbacks _initialize_callbacks _read_atsortingbute _reflections _reflections? _rollback_callbacks _rollback_without_transaction_enrollment_callbacks _run_before_commit_callbacks _run_before_commit_without_transaction_enrollment_callbacks _run_commit_callbacks _run_commit_without_transaction_enrollment_callbacks _run_create_callbacks _run_destroy_callbacks _run_find_callbacks _run_initialize_callbacks _run_rollback_callbacks _run_rollback_without_transaction_enrollment_callbacks _run_save_callbacks _run_touch_callbacks _run_update_callbacks _run_validate_callbacks _run_validation_callbacks _save_callbacks _touch_callbacks _update_callbacks _validate_callbacks _validation_callbacks _validators _validators? ` accessed_fields acts_like? add_to_transaction aggregate_reflections aggregate_reflections? as_json assign_atsortingbutes association association_cached? atsortingbute_aliases atsortingbute_aliases? atsortingbute_before_last_save atsortingbute_change atsortingbute_change_to_be_saved atsortingbute_changed? atsortingbute_changed_in_place? atsortingbute_for_inspect atsortingbute_in_database atsortingbute_method_matchers atsortingbute_method_matchers? atsortingbute_missing atsortingbute_names atsortingbute_present? atsortingbute_previously_changed? atsortingbute_was atsortingbutes atsortingbutes= atsortingbutes_before_type_cast atsortingbutes_changed_by_setter atsortingbutes_in_database becomes becomes! before_committed! blank? byebug cache_key cache_timestamp_format cache_timestamp_format? changed changed? changed_atsortingbute_names_to_save changed_atsortingbutes changed_for_autosave? changes changes_applied changes_internally_applied changes_to_save class class_eval clear_atsortingbute_changes clear_changes_information clone column_for_atsortingbute committed! connection_handler debugger decrement decrement! deep_dup default_connection_handler default_connection_handler? default_scope_override default_scopes default_timezone define_singleton_method defined_enums defined_enums? delete destroy destroy! destroyed? destroyed_by_association destroyed_by_association= display dump_schema_after_migration dump_schemas dup duplicable? encode_with enum_for eql? equal? error_on_ignored_order error_on_ignored_order_or_limit errors extend freeze from_json frozen? gem has_atsortingbute? has_changes_to_save? hash html_safe? id id= id? id_before_type_cast id_in_database id_was in? include_root_in_json include_root_in_json? increment increment! index_nested_atsortingbute_errors init_with initialize_internals_callback inspect instance_eval instance_exec instance_of? instance_values instance_variable_defined? instance_variable_get instance_variable_names instance_variable_set instance_variables invalid? is_a? itself kind_of? load_dependency lock! lock_optimistically lock_optimistically? locking_enabled? logger mark_for_destruction marked_for_destruction? method method_missing methods model_name nested_atsortingbutes_options nested_atsortingbutes_options? new_record? nil? no_touching? object_id partial_writes partial_writes? persisted? pluralize_table_names pluralize_table_names? populate_with_current_scope_atsortingbutes presence presence_in present? pretty_inspect pretty_print pretty_print_cycle pretty_print_inspect pretty_print_instance_variables previous_changes primary_key_prefix_type private_methods protected_methods pry public_method public_methods public_send query_atsortingbute quoted_id raw_write_atsortingbute read_atsortingbute read_atsortingbute_before_type_cast read_atsortingbute_for_serialization read_atsortingbute_for_validation readonly! readonly? record_timestamps record_timestamps= record_timestamps? reload remote_byebug remove_instance_variable require_dependency require_or_load respond_to? respond_to_without_atsortingbutes? restore_atsortingbutes rollback_active_record_state! rolledback! run_callbacks save save! saved_change_to_atsortingbute saved_change_to_atsortingbute? saved_changes saved_changes? schema_format send serializable_hash singleton_class singleton_method singleton_methods skip_time_zone_conversion_for_atsortingbutes skip_time_zone_conversion_for_atsortingbutes? slice store_full_sti_class store_full_sti_class? suppress_warnings table_name_prefix table_name_prefix? table_name_suffix table_name_suffix? taint tainted? tap time_zone_aware_atsortingbutes time_zone_aware_types time_zone_aware_types? timestamped_migrations to_enum to_gid to_gid_param to_global_id to_json to_key to_model to_param to_partial_path to_query to_s to_sgid to_sgid_param to_signed_global_id to_yaml toggle toggle! touch touch_later transaction trust try try! type_for_atsortingbute unloadable untaint untrust untrusted? update update! update_atsortingbute update_atsortingbutes update_atsortingbutes! update_column update_columns valid? validate validate! validates_absence_of validates_acceptance_of validates_confirmation_of validates_exclusion_of validates_format_of validates_inclusion_of validates_length_of validates_numericality_of validates_presence_of validates_size_of validates_with validation_context warn_on_records_fetched_greater_than will_save_change_to_atsortingbute? with_lock with_options with_transaction_returning_status write_atsortingbute yield_self 

Vous pouvez l’obtenir avec

 ActiveRecord::Base.instance_methods.sort