nownabe/database_cleaner-spanner

View on GitHub
example/rails/app/models/song.rb

Summary

Maintainability
A
0 mins
Test Coverage
class Song < ApplicationRecord
  self.primary_keys = :singerid, :albumid, :songid
  belongs_to :album, foreign_key: [:singerid, :albumid]
  belongs_to :singer, foreign_key: :singerid

  def initialize(attributes = nil)
    super
    self.singer ||= album&.singer
  end

  def album=(album)
    super
    self.singer = album&.singer
  end
end