Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix #1016

  • Loading branch information...
commit 3c54cae0ec9982621c5c7e958cadc803bd776422 1 parent 299f2e1
@nafg nafg authored
View
12 persistence/mapper/src/main/scala/net/liftweb/mapper/ManyToMany.scala
@@ -102,8 +102,16 @@ trait ManyToMany extends BaseKeyedMapper {
removedJoin // well, noLongerRemovedJoin...
case None =>
val newJoin = joinMeta.create
- field(newJoin).set(ManyToMany.this.primaryKeyField.is)
- otherField.actualField(newJoin).set(e.primaryKeyField.is)
+ val joinParentFK = field(newJoin)
+ joinParentFK.set(ManyToMany.this.primaryKeyField.is)
+ joinParentFK match {
+ case mfk: MappedForeignKey[_,_,T] => mfk.primeObj(Full(ManyToMany.this))
+ }
+ val joinChildFK = otherField.actualField(newJoin)
+ joinChildFK.set(e.primaryKeyField.is)
+ joinChildFK match {
+ case mfk: MappedForeignKey[_,_,T2] => mfk.primeObj(Full(e))
+ }
newJoin
}
case Some(join) =>
View
21 persistence/mapper/src/test/scala/net/liftweb/mapper/ManyToManySpecs.scala
@@ -67,6 +67,25 @@ object ManyToManySpec extends Specification("ManyToMany Specification") {
person.companies.insertAll(7, Seq(c))
person.companies(7).name.is must_== "new"
}
+
+
+// from Florian
+
+ "count unsaved children" in {
+ setupDB
+ val person = new Person
+ val company = new Company
+ person.companies += company
+ person.companies.length must_== 1
+ }
+ "count saved children" in {
+ setupDB
+ val person = new Person
+ val company = new Company
+ company.save
+ person.companies += company
+ person.companies.length must_== 1
+ }
}
}
@@ -89,6 +108,8 @@ class PersonCompany extends Mapper[PersonCompany] {
def getSingleton = PersonCompany
object person extends MappedLongForeignKey(this, Person)
object company extends MappedLongForeignKey(this, Company)
+
+ override def toString = "PersonCompany(person.is=%s, person.obj=%s, company.is=%s, company.obj=%s)".format(person.is,person.obj,company.is,company.obj)
}
object PersonCompany extends PersonCompany with MetaMapper[PersonCompany]

0 comments on commit 3c54cae

Please sign in to comment.
Something went wrong with that request. Please try again.