Sha256: 4b2d57a01237befb36ccdcb7ad1b59ddf21d79e7b36c6ba092af6298afaf265e
Contents?: true
Size: 862 Bytes
Versions: 3
Compression:
Stored size: 862 Bytes
Contents
# Copyright 2021 Google LLC # # Use of this source code is governed by an MIT-style # license that can be found in the LICENSE file or at # https://opensource.org/licenses/MIT. class Track < ActiveRecord::Base # `tracks` is defined as INTERLEAVE IN PARENT `albums`. The primary key of `albums` is ()`singerid`, `albumid`). belongs_to :album, foreign_key: "albumid" # `tracks` also has a `singerid` column should be used to associate a Track with a Singer. belongs_to :singer, foreign_key: "singerid" # Override the default initialize method to automatically set the singer attribute when an album is given. def initialize attributes = nil super self.singer ||= album&.singer end def album=value super # Ensure the singer of this track is equal to the singer of the album that is set. self.singer = value&.singer end end
Version data entries
3 entries across 3 versions & 1 rubygems