Issues with EmbeddedField

3 views
Skip to first unread message

Heiko Seeberger

unread,
Oct 20, 2010, 1:03:01 PM10/20/10
to mongo-scala-driver
Hi,

Any ideas why the following code won't compile?

package wontcompile

import java.util.Locale
import com.osinka.mongodb.shape. {ObjectIn, MongoObjectShape}
import com.mongodb.DBObject
import com.osinka.mongodb.MongoObject

trait AttrOptionIn[A] extends ObjectIn[AttrOption, A] {

lazy val value = Field.scalar("value", _.value)

lazy val name = new EmbeddedField[I18nName]("name", _.name, None)
with I18nNameIn[AttrOption]

lazy val * = value :: name :: Nil

def factory(dbo: DBObject): Option[AttrOption] =
for {
value(v) <- Some(dbo)
name(n) <- Some(dbo)
} yield AttrOption(v, null )
}

case class AttrOption(value: Int, name: I18nName) extends MongoObject

trait I18nNameIn[A] extends ObjectIn[I18nName, A] {

lazy val de = Field.optional("de", _.de)

lazy val en = Field.optional("en", _.de)

lazy val fr = Field.optional("fr", _.de)

lazy val it = Field.optional("it", _.de)

lazy val * = de :: en :: fr :: it :: Nil

def factory(dbo: DBObject): Option[I18nName] =
for {
de(d) <- Some(dbo)
en(e) <- Some(dbo)
fr(f) <- Some(dbo)
it(i) <- Some(dbo)
} yield I18nName(Option(d), Option(e), Option(f), Option(i))
}

object I18nName extends MongoObjectShape[I18nName] with
I18nNameIn[I18nName]

case class I18nName(
de: Option[String] = None,
en: Option[String] = None,
fr: Option[String] = None,
it: Option[String] = None) extends MongoObject {

def name(implicit locale: Locale): String = {
import Locale._
locale match {
case GERMAN => de getOrElse mongoOID.toString
case ENGLISH => de getOrElse mongoOID.toString
case FRENCH => de getOrElse mongoOID.toString
case ITALIAN => de getOrElse mongoOID.toString
case _ => mongoOID.toString
}
}
}

This is the error message:

[error] /Users/hseeberger/projects/ism/src/test/scala/
wontcompile.scala:12: illegal inheritance;
[error] self-type
AttrOptionIn.this.EmbeddedField[wontcompile.I18nName] with
wontcompile.I18nNameIn[wontcompile.AttrOption] does not conform to
AttrOptionIn.this.EmbeddedField[wontcompile.I18nName]'s selftype
AttrOptionIn.this.EmbeddedField[wontcompile.I18nName] with
AttrOptionIn.this.MongoField[wontcompile.I18nName] with
com.osinka.mongodb.shape.ObjectIn[wontcompile.I18nName,A]
[error] lazy val name = new EmbeddedField[I18nName]("name", _.name,
None) with I18nNameIn[AttrOption]
[error] ^

Thanks,

Heiko

Heiko Seeberger

unread,
Oct 20, 2010, 2:21:45 PM10/20/10
to mongo-scala-driver
Hehe, answering my own question:

  lazy val name = new EmbeddedField[I18nName]("name", _.name, None) with I18nNameIn[A]

instead of

  lazy val name = new EmbeddedField[I18nName]("name", _.name, None) with I18nNameIn[AttrOption]

Well, Scala's type system sometimes is really tricky ...

Heiko
--
Heiko Seeberger

Company: weiglewilczek.com
Blog: heikoseeberger.name
Follow me: twitter.com/hseeberger
OSGi on Scala: scalamodules.org
Lift, the simply functional web framework: liftweb.net
Akka - Simpler Scalability, Fault-Tolerance, Concurrency & Remoting through Actors: akkasource.org

Alexander Azarov

unread,
Oct 20, 2010, 5:42:11 PM10/20/10
to mongo-scala-driver


On Oct 20, 10:21 pm, Heiko Seeberger <heiko.seeber...@googlemail.com>
wrote:
> Hehe, answering my own question:
>
>   lazy val name = new EmbeddedField[I18nName]("name", _.name, None) with
> I18nNameIn[A]
>
> instead of
>
>   lazy val name = new EmbeddedField[I18nName]("name", _.name, None) with
> I18nNameIn[AttrOption]

Yup, the query generated by the field must be generalized with the
enclosing Shape...

> Well, Scala's type system sometimes is really tricky ...

True.

>
> Heiko
Reply all
Reply to author
Forward
0 new messages