Как я могу реализовать график с ассоциациями моей активной записи в рельсах? - PullRequest
0 голосов
/ 19 января 2019

У меня есть все ассоциации внешних ключей на уровне приложения с рельсами Active record и ни одной на db. Я хочу реализовать график (структуру данных) с этими отражениями 150 таблиц, а также могу ли я получить все отражения каждой модели за один разВ настоящее время я получаю отражение для каждой таблицы вручную, как это User.reflections.

И получаю это:

{"audits"=>
  #<ActiveRecord::Reflection::HasManyReflection:0x00007faa1a75fc08
   @active_record=
    User(id: integer, email: string, encrypted_password: string, reset_password_token: string, reset_password_sent_at: datetime, remember_created_at: datetime, sign_in_count: integer, current_sign_in_at: datetime, last_sign_in_at: datetime, current_sign_in_ip: string, last_sign_in_ip: string, confirmation_token: string, confirmed_at: datetime, confirmation_sent_at: datetime, unconfirmed_email: string, created_at: datetime, updated_at: datetime, first_name: string, last_name: string, date_of_birth: datetime, guid: string, mobile_no: string, gender: integer, status: integer, authentication_token: string, is_internal_employee: boolean),
   @association_scope_cache={},
   @automatic_inverse_of=nil,
   @constructable=true,
   @foreign_type="audits_type",
   @klass=nil,
   @name=:audits,
   @options={:as=>:auditable, :class_name=>"Audited::Audit"},
   @plural_name="audits",
   @scope=#<Proc:0x00007faa1a75fd20@/Users/vipulmaan/.rvm/gems/ruby-2.4.3/gems/activerecord-5.1.4/lib/active_record/associations/builder/association.rb:55>,
   @scope_lock=#<Thread::Mutex:0x00007faa1a75f618>,
   @type="auditable_type">,

1 Ответ

0 голосов
/ 19 января 2019

Одной из возможностей получения отражений всех ваших моделей было бы перебрать потомков вашего ApplicationRecord класса.

all_reflections = ApplicationRecord.descendants.map(&:reflections)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...