kclay / rethink-scala

Scala Driver for RethinkDB
Other
100 stars 24 forks source link

Problem inserting nested Document type #19

Closed ohde closed 9 years ago

ohde commented 9 years ago

user is of type User extends Document and includes another type extending Document.

Fails:

insert(user)

Client is buggy (failed to deserialize query).

Works:

insertMap(Seq(Reflector.toMap(user))
ohde commented 9 years ago

This is a newly introduced bug, as all of my nested inserts no longer work.

kclay commented 9 years ago

Can u give me an example of your case class declaration so I can make a test

On October 1, 2014 9:46:53 PM CDT, Michael notifications@github.com wrote:

This is a newly introduced bug, as all of my nested inserts no longer work.


Reply to this email directly or view it on GitHub: https://github.com/kclay/rethink-scala/issues/19#issuecomment-57574395

ohde commented 9 years ago
case class Address(labels: List[String] = List("sample")) extends Document

case class User(name: String, active: Boolean = true, address: Address = Address(), id: Option[String] = None) extends Document
kclay commented 9 years ago

Fixed in 0.4.5. Sorry for the delay

ohde commented 9 years ago

Thanks worked great.

ohde commented 9 years ago

Please reopen. I had to switching back to using: insertMap(Seq(Reflector.toMap(user))

kclay commented 9 years ago

I'll check this one today

On February 1, 2015 4:16:46 AM CST, Michael notifications@github.com wrote:

Please reopen. I had to switching back to using: insertMap(Seq(Reflector.toMap(user))


Reply to this email directly or view it on GitHub: https://github.com/kclay/rethink-scala/issues/19#issuecomment-72359119

kclay commented 9 years ago

Can't you provide a example of your document. Here is my current test and it seems to be passing:

case class NestedAddress(labels: List[String]) extends Document

case class NestedUser(name: String, active: Boolean , address: NestedAddress, id: Option[String] = None) extends Document

class NestedTest extends FunSuite with WithBase {

  test("nested documents") {

    val user = NestedUser("foo",true,NestedAddress(List("hello")))
    val foos= r.tableAs[NestedUser]("foo")
    val term = foos.insert(user)
    val query = version3.toQuery(term, 1, None, Map.empty)
    val json = query.json
    println(json)
   val answer =for {
      res <- term.toOpt
      user2 <- foos.get(res.generatedKeys.head).toOpt
    } yield user2

    println(answer) 
// Some(NestedUser(foo,true,NestedAddress(List(hello)),Some(d0189ff4-70fa-46c0-bc6a-cee5450a5b64)))

  }

}```
kclay commented 9 years ago

Tested a few more nested

case class NestedZip(zip:String) extends Document
case class NestedStreet(zip:NestedZip) extends Document
case class NestedAddress(street:NestedStreet) extends Document
case class NestedUser(name: String, active: Boolean , address: NestedAddress, id: Option[String] = None) extends Document

I would double check that all case classes extend Document

ohde commented 9 years ago

I see the difference. My user case class includes an object that doesn't inherit from Document as it is from an imported class and is inserting null value for that field.

However, this was not always the case, 0.4.4 allows me to insert this object with no problem. Let me know if you need me to provide further examples.