Files
has_aux_table/backlog/tasks/task-4 - Set-up-ActiveRecord-associations.md
2025-07-14 17:32:58 +00:00

1.4 KiB

id, title, status, assignee, created_date, updated_date, labels, dependencies
id title status assignee created_date updated_date labels dependencies
task-4 Set up ActiveRecord associations Done
2025-07-13 2025-07-13

Description

Create the has_one association between STI class and auxiliary table

Acceptance Criteria

  • has_one association is created automatically
  • Foreign key is properly configured
  • Association name is consistent and predictable

Implementation Plan

  1. Analyze existing implementation in generate_aux_model_class method
  2. Verify has_one association is properly configured with correct foreign key
  3. Ensure association name follows consistent naming convention
  4. Update task documentation to mark completion

Implementation Notes

The has_one association was already implemented in the generate_aux_model_class method in task-3. The implementation correctly:

  • Creates has_one association automatically when aux_table is defined
  • Uses proper foreign key configuration based on base STI class (e.g., vehicle_id for Vehicle STI)
  • Follows consistent naming convention using table_name.to_s.singularize.to_sym
  • Supports lazy loading as standard ActiveRecord has_one associations do

The association is set up in lines 158-162 of lib/has_aux_table.rb:

T.unsafe(self).has_one(
  table_name.to_s.singularize.to_sym,
  class_name: class_name,
  foreign_key: "#{base_class_name}_id"
)

All tests pass and the implementation meets all acceptance criteria.