mapperdao manytoone - getting hold of id's

32 Aufrufe
Direkt zur ersten ungelesenen Nachricht

Jan Hansen

ungelesen,
26.10.2012, 07:31:4926.10.12
an scala...@googlegroups.com
I try to get hold of the id of an entity through a
manytoone mapping, but unsuccessful so far.

This is a very stripped down version,
and I hope my question still make sense.

=== ENTITIES =====
object A_Entity extends Entity[IntId, A] {
val id = key("id") sequence seq("A_SEQ") autogenerated (_.id)
val name = column("name") to (_.name)

def constructor(implicit m:ValuesMap) =
new A(name) with IntId with Persisted {

val id: Int = A_Entity.id
}
}

-----

object B_Entity extends Entity[IntId, B] {
val id = key("id") sequence seq("B_SEQ") autogenerated (_.id)
val A_item = manytoone(A_Entity) foreignkey("A_item_id") to (_.A_item)

def constructor(implicit m:ValuesMap) =
new B(A_item) with Persisted with IntId {

val id: Int = B_Entity.id
}
}

=== MODELS =====
case class A (
val name: String,
)

object A {
def empty = new A("")
}

-----

case class B(
val title: String,
val A_item:A,
)

object B {
def empty = new B(new A("")
}

=== DAOS ===
abstract class A_Dao extends TransactionalIntIdCRUD[A] with IntIdAll[A] {
entity = A_Entity
}

-----

abstract class B_Dao extends TransactionalIntIdCRUD[B] with IntIdAll[B] {
val entity = B_Entity
}


=== BUSINESS LOGIC ===
val B_all = B_Dao.all

b <- B_all
if (true) b.A_item.id // DOES NOT EXIST

I can access the A_item.name but not the A_item.id
How can I get hold of A_item's id ?




Flávio W. Brasil

ungelesen,
26.10.2012, 21:52:1426.10.12
an Jan Hansen, scala...@googlegroups.com
Do you know Activate? Is much simpler:

case class A(name: String) extends Entity
case class B(title: String, item: A) extends Entity

val bAll = all[B]
val ids = bAll.map(_.id)

The ID is available at any time and there is no need for empty constructors, DAOs and separate entity declaration.

-- 
Flávio W. Brasil

Kostas kougios

ungelesen,
31.10.2012, 19:49:3531.10.12
an scala...@googlegroups.com, sl07...@hotmail.com
Try Helpers.intIdOf(...). There are more useful methods available in that object.

Allen antworten
Antwort an Autor
Weiterleiten
0 neue Nachrichten