Created
October 1, 2012 22:22
-
-
Save tdm00/3814822 to your computer and use it in GitHub Desktop.
Associations to deep?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Patient < ActiveRecord::Base | |
# Associations | |
has_many :Requisitions | |
# Functions | |
def full_name | |
return [given_name, family_name].join(' ') | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This correctly finds the record | |
rt = RequisitionTest.find(323) | |
# This correctly displays the patients name | |
rt.Requisition.Patient.full_name | |
# This fails with undefined method `datereported' for #<ActiveRecord::Relation:0x00000000000000> | |
# However doing rt.RequisitionTestReports shows the datereported field with a date/time value | |
rt.RequisitionTestReports.datereported | |
# This also fails with undefined method `ReportType' for #<ActiveRecord::Relation:0x00000000000000> | |
rt.RequisitionTestReports.ReportType.name | |
# However this works | |
r = RequisitionTestReport.find(420) | |
r.ReportType.name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ReportType < ActiveRecord::Base | |
# Associations | |
has_many :RequisitionTestReports | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Requisition < ActiveRecord::Base | |
# Associations | |
has_many :RequisitionTests | |
belongs_to :Patient | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RequisitionTest < ActiveRecord::Base | |
# Associations | |
belongs_to :Requisition | |
has_many :RequisitionTestReports | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RequisitionTestReport < ActiveRecord::Base | |
# Associations | |
belongs_to :RequisitionTest | |
belongs_to :ReportType | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment