using rogue with abstract records or records with certain type?

14 views
Skip to first unread message

Otto

unread,
Oct 16, 2013, 11:08:01 AM10/16/13
to rogue...@googlegroups.com
Hi,

I have a trait which mixes some attributes into some other records. But I'm struggling to write generic controller code which only operates on the attributes defined by the relevant trait. because the implicits don't kick in.

Any Ideas?


trait CRRatingModel[RATING <: MongoRecord[RATING] with CRRatingRecord[RATING]] {

  def getAllRatings()(ratingRecord: RATING) = {
    val noRating = ratingRecord
    .where(_.id eqs new ObjectId())
    .get()

    val allRatings = ratingRecord
    .fetch()
  }
}

Thanks,
Otto



Jason Liszka

unread,
Oct 16, 2013, 4:24:50 PM10/16/13
to rogue...@googlegroups.com
Maybe you need RATING <: MongoMetaRecord[RATING]? The standard trick is to try to apply the implicit conversion explicitly and see why the compiler doesn't like it.


--
You received this message because you are subscribed to the Google Groups "rogue-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rogue-users...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Otto

unread,
Oct 17, 2013, 6:22:06 AM10/17/13
to rogue...@googlegroups.com

Otto

unread,
Oct 17, 2013, 6:22:56 AM10/17/13
to rogue...@googlegroups.com
Thanks Jason,

your trick was helpful. After loads of try and error i came to this solution:

trait CRRatingModel[RATING <: MongoRecord[RATING] with CRRatingRecord[RATING] with MongoMetaRecord[RATING]] {

  self: RATING =>

  

  def getAllRatings() = {

    val foo = self.where(_.rating eqs 5).fetch()

Otto

unread,
Oct 17, 2013, 9:13:15 AM10/17/13
to rogue...@googlegroups.com
Ok, the code compiled but wasn't "consumable". I now went with the following. Not as nice, but it works, maybe there's a nicer solution.

trait CRRatingModel[RATING <: MongoRecord[RATING] with CRRatingRecord[RATING], RATINGMETA <: RATING with MongoMetaRecord[RATING]] {

//trait CRRatingModel[RATING <: MongoRecord[RATING] with CRRatingRecord[RATING] with MongoMetaRecord[RATING]] {

  def RecordType: RATINGMETA

  

  def getAllRatings() = {

    val foo = RecordType.where(_.rating eqs 5).fetch()

    foo

  }

}


Otto

Reply all
Reply to author
Forward
0 new messages