У меня прямое отношение has_many через мое приложение RoR3.2.1. Единственное изменение заключается в том, что я использую другой внешний / первичный ключ при работе с устаревшей базой данных.
По какой-то причине, когда я создаю новую запись, значения сохраняются в неправильных полях. Имя группы сохраняется в имени пользователя и наоборот.
У моих raduser есть много радгрупп через radusergroups. Моя объединяющая таблица содержит столбцы username и groupname.
Raduser.rb:
has_many :radusergroup, :dependent => :destroy, :foreign_key => :groupname, :primary_key => :username
has_many :radgroup, :through => :radusergroup
Radgroup.rb:
has_many :radusergroup, :dependent => :destroy
has_many :raduser, :through => :radusergroup
Radusergroup.rb
belongs_to :raduser, :primary_key => :username
belongs_to :radgroup, :primary_key => :groupname, :foreign_key => :username
У меня есть это в моей форме:
- Radgroup.all.each do |radgroup|
= check_box_tag "raduser[radgroup_ids][]", radgroup.id, @raduser.radgroup.include?(radgroup), :id => "raduser_radgroup_id_#{radgroup.id}"
= radgroup.groupname
Когда я нажимаю "Сохранить", мои записи сохраняются неправильно:
INSERT INTO `radusergroup` (`groupname`, `id`, `priority`, `username`) VALUES ('username1233', NULL, 1, 'groupname123')
и таблица:
+------------------+--------------+----------+----+
| username | groupname | priority | id |
+------------------+--------------+----------+----+
| groupname123 | username1233 | 1 | 1 |
+------------------+--------------+----------+----+
Кто-нибудь может помочь с этим?
---- РЕДАКТИРОВАТЬ ДОБАВЛЕННУЮ СЛЕДУЮЩУЮ СЛЕДУЮЩУЮ СЛЕДУЮЩУЮ ОТВЕТА ----
actionpack (3.2.1) lib/action_controller/metal/hide_actions.rb:36:in `visible_action?'
actionpack (3.2.1) lib/action_controller/metal/hide_actions.rb:18:in `method_for_action'
actionpack (3.2.1) lib/action_controller/metal/implicit_render.rb:14:in `method_for_action'
actionpack (3.2.1) lib/action_controller/metal/compatibility.rb:61:in `method_for_action'
actionpack (3.2.1) lib/abstract_controller/base.rb:115:in `process'
actionpack (3.2.1) lib/abstract_controller/rendering.rb:45:in `process'
actionpack (3.2.1) lib/action_controller/metal.rb:203:in `dispatch'
actionpack (3.2.1) lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
actionpack (3.2.1) lib/action_controller/metal.rb:246:in `block in action'
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:66:in `call'
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:66:in `dispatch'
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:30:in `call'
journey (1.0.1) lib/journey/router.rb:68:in `block in call'
journey (1.0.1) lib/journey/router.rb:56:in `each'
journey (1.0.1) lib/journey/router.rb:56:in `call'
actionpack (3.2.1) lib/action_dispatch/routing/route_set.rb:589:in `call'
warden (1.1.0) lib/warden/manager.rb:35:in `block in call'
warden (1.1.0) lib/warden/manager.rb:34:in `catch'
warden (1.1.0) lib/warden/manager.rb:34:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
rack (1.4.1) lib/rack/etag.rb:23:in `call'
rack (1.4.1) lib/rack/conditionalget.rb:25:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/head.rb:14:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/params_parser.rb:21:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/flash.rb:242:in `call'
rack (1.4.1) lib/rack/session/abstract/id.rb:205:in `context'
rack (1.4.1) lib/rack/session/abstract/id.rb:200:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/cookies.rb:338:in `call'
activerecord (3.2.1) lib/active_record/query_cache.rb:64:in `call'
activerecord (3.2.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:443:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `_run__2911347278127141110__call__2925805972906996448__callbacks'
activesupport (3.2.1) lib/active_support/callbacks.rb:405:in `__run_callback'
activesupport (3.2.1) lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
activesupport (3.2.1) lib/active_support/callbacks.rb:81:in `run_callbacks'
actionpack (3.2.1) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/reloader.rb:65:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
railties (3.2.1) lib/rails/rack/logger.rb:26:in `call_app'
railties (3.2.1) lib/rails/rack/logger.rb:16:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/request_id.rb:22:in `call'
rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
rack (1.4.1) lib/rack/runtime.rb:17:in `call'
activesupport (3.2.1) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
rack (1.4.1) lib/rack/lock.rb:15:in `call'
actionpack (3.2.1) lib/action_dispatch/middleware/static.rb:53:in `call'
railties (3.2.1) lib/rails/engine.rb:479:in `call'
railties (3.2.1) lib/rails/application.rb:220:in `call'
rack (1.4.1) lib/rack/content_length.rb:14:in `call'
railties (3.2.1) lib/rails/rack/log_tailer.rb:14:in `call'
rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'
/usr/local/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
/usr/local/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
/usr/local/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
--- СЕССИЯ DUMP ---
_csrf_token: "YepneklJ9OWdmKHVVclxGzrg5ECbk11a9B3tJJtoECU="
session_id: "8cec81c93085d17dc744f1a44a7054b6"
warden.user.user.key: ["User", [1], "$2a$10$J.oF0HRrE0PokqkQ2S4gwO"]