I have a Brand class that has several products
And in the product class I want to have a reference to the brand, like this:
case class Brand(val name:String, val products: List[Product])
case class Product(val name: String, val brand: Brand)
How can I poulate these classes???
I mean, I can't create a product unless I have a brand
And I can't create the brand unless I have a list of Products (because Brand.products is a val)
What would be the best way to model this kind of relation?
Since your question is about model to this relationship, I will say why not just model them like what we do in database? Separate the entity and the relationship.
I would question why you are repeating the information, by saying which products relate to which brand in both the List and in each Product.
Still, you can do it:
By-name params don't seem to be allowed for case classes unfortunately.
See also this similar question: Instantiating immutable paired objects