# How to reference a collection from another collection?
Define the property as reference in the collection. For example:
collection Address { property line1:String property line2:String property city:String property state:String } collection Employee { property name:String property designation:String reference address:Address }enter sbt shell, run command
compileNote: In terms of the fields in the collection, only the object Id of the referenced collection is stored. For example: address is stored address_oid inside employee collection
# Sample Usage:
//Create
def addEmployee(): Unit = {
val addressRow = AddressRow(_id = new Id,
line1 = "No 123, 4th Street", city = "Bangalore", state = "Karnataka")
AddressWriter().insert(addressRow)
val empRow = EmployeeRow(
name = "Vivitsa", designation = "HR",
address_oid = addressRow._id)
EmployeeWriter().insert(empRow)
}
//Read
def getResidentCity(employeeId:Id):String = {
val empRow = EmployeeQuery.findById(employeeId).get
empRow.address.city
}