fwbrasil / activate

Abandoned: Pluggable persistence in Scala
GNU Lesser General Public License v2.1
299 stars 46 forks source link

Query generic Entity #132

Closed odwrotnie closed 10 years ago

odwrotnie commented 10 years ago

You can't create query with generic Entity, for example abstract class Action[T](var name: String) extends Entity

[error] /.../Action.scala:89: no type parameters for method query: (f: E1 => net.fwbrasil.activate.statement.query.Query[S])(implicit evidence$5: Manifest[E1])List[S] exist so that it can be applied to arguments (model.actions.Action[_] => net.fwbrasil.activate.statement.query.Query[model.actions.Action[_$4(in value $anonfun)]] forSome { type _$4(in value $anonfun) })
[error]  --- because ---
[error] argument expression's type is not compatible with formal parameter type;
[error]  found   : model.actions.Action[_] => net.fwbrasil.activate.statement.query.Query[model.actions.Action[_$4(in value $anonfun)]] forSome { type _$4(in value $anonfun) }
[error]  required: ?E1 => net.fwbrasil.activate.statement.query.Query[?S]
[error]   def byUser(user: User) = query {
[error]                            ^
[error] one error found
odwrotnie commented 10 years ago

The Entity (TreeNode extends Entity):

abstract class Action[T](var name: String)
  extends TreeNode[Action[_]]
  with Whose
  with Logger {

The Query:

  def byUser(user: User) = query {
    (action: Action[_]) =>
      where(action.owner :== user)
        .select(action)
        .orderBy(action.created)
  }
fwbrasil commented 10 years ago

As discussed via Skype, it is necessary to specify the Action generic parameter, since the scala type inference can handle this pattern of usage.