Im using Scala, Squeryl and MySql to build a web app.
I found it easy to persist simple data as strings or integers. But what about when i have relations between objects and i need to use foreign keys. In my app i have areas, and sub areas which have an attribute of type Area (Area where they belong) so my Area and Subarea are like these
class Area(
var idArea: String,
@BeanProperty
var name:String,
@BeanProperty
var letter: String,
@BeanProperty
var color: String
)
extends Idable {
def this() = this("","", "","")
}
class SubArea(var idSubArea: String,
@BeanProperty
var name: String,
@BeanProperty
var area:Area
) extends Idable {
def this() = this("","",null )
How do i define the schema, so my SubArea table has an Area id, foreign key to my Area Table?? For the time being my SubArea schema is like these
object SubAreaSchema extends Schema {
val subAreas=table[SubArea]
on(subAreas)(subArea => declare(
subArea.id is (autoIncremented),
subArea.name is (unique)
))
}