Manage table associations
masterAirrecord supports has_many, has_one, and belongs_to associations between Airrecord::Table classes, provided they reside in the same Airtable base.
Retrieving Associated Records
- Calling the association method on a record returns an array of
Airrecordinstances (forhas_many) or a single instance (forhas_one). - Accessing the raw column via
[]returns the raw Airtable field (usually an array of IDs).
Creating Associations
You can associate records by assigning the instance of the parent record to the child record's association method before calling #create (or #save).
# Setup
class Tea < Airrecord::Table
has_many :brews, class: "Brew", column: "Brews"
end
class Brew < Airrecord::Table
belongs_to :tea, class: "Tea", column: "Tea"
end
# Usage: Creating an association
tea = Tea.find("rec123")
brew = Brew.new("Temperature" => "80")
brew.tea = tea
brew.create