Permalink
Browse files

Mapper: Make ManyToMany use FieldFinder too

  • Loading branch information...
nafg committed May 25, 2011
1 parent 461ffaa commit 77f6e67e5472e1121799930dc885516bd32c4ab7
@@ -30,7 +30,12 @@ trait ManyToMany extends BaseKeyedMapper {
type K = TheKeyType
type T = KeyedMapperType
- private var manyToManyFields: List[MappedManyToMany[_,_,_]] = Nil
+ private[mapper] lazy val manyToManyFields: List[MappedManyToMany[_,_,_]] = {
+ new FieldFinder[MappedManyToMany[_,_,_]](
+ getSingleton,
+ net.liftweb.common.Logger(classOf[ManyToMany])
+ ).accessorMethods map (_.invoke(this).asInstanceOf[MappedManyToMany[_,_,_]])
+ }
/**
* An override for save to propagate the save to all children
@@ -89,7 +94,6 @@ trait ManyToMany extends BaseKeyedMapper {
refresh
- manyToManyFields ::= this
protected def isJoinForChild(e: T2)(join: O) = otherField.actualField(join).is == e.primaryKeyField.is
protected def joinForChild(e: T2): Option[O] =
@@ -67,6 +67,13 @@ object ManyToManySpec extends Specification("ManyToMany Specification") {
person.companies.insertAll(7, Seq(c))
person.companies(7).name.is must_== "new"
}
+ "detect all MappedManyToMany fields" in {
+ setupDB
+ val person = Person.create
+ val fields = person.manyToManyFields
+ fields.length must_== 1
+ fields(0).asInstanceOf[Any] must_== person.companies
+ }
// from Florian

0 comments on commit 77f6e67

Please sign in to comment.