Query to Class map

94 views
Skip to first unread message

Oleg Kiriltsev

unread,
May 22, 2012, 6:13:29 PM5/22/12
to scala...@googlegroups.com
Hi,

i have two tables:
t1(a,b,c)
t2(c,d)
in Relation 1 to many: for each data record from t1 is many records in t2

c in t1 is foreign key.

How i can map all records from t2 (for example for c = 555) to List in Class t11?

case class t1(a: Int, b: String, c: Int, d_list: List[Int])

object t11 extends Table[t1]("t1"){
 
def a = column[Int]("a")
def b = column[String]("b")
def c = column[Int]("c") 
//need: all records from t2 as List for this record from t1 AUTOMATIC
def d_list =  List[t2.d] 
// i think maybe with def mapped, but how !? 
def t2_d = foreignKey("C_FK", c, analysis_names)(_.c)
}

case class t2(c: Int, d: Int)

object t22 extends Table[t2]("t2"){
 
def c = column[Int]("c")
def d = column[Int]("d")
}

have idea!?
Sorry for my english.

Alles noch mal auf deutsch:

Ich habe die zwei Tabellen,die in der Beziehung 1 zu n stehen. Ich will, die Klasse definieren so, dass alle Datensätze von der Tabelle t2, die zum Eintrag von der Tabelle t1 gehören, als Liste in der Klasse t1 automatisch geliefert werden. Ich glaube, dass es irgenwie mit  <def mapped> gehen muss, aber ich weiss es nicht, wie ich dass defeniere.

Hat jemand Ideen!?

best regards / freundliche Grüße

Oleg

Oleg Kiriltsev

unread,
May 22, 2012, 6:25:17 PM5/22/12
to scala...@googlegroups.com
I've forgotten 

def * = a ~ b ~ c

and

def * = c ~ d

and error

def t2_d = foreignKey("C_FK", c, t22)(_.c) 


object t11 extends Table[t1]("t1"){ 
...
def mapped = t22.+ <> ((c, d) ⇒ List(d), ???.unapply) 
}

best regards

Oleg

среда, 23 мая 2012 г., 0:13:29 UTC+2 пользователь Oleg Kiriltsev написал:

среда, 23 мая 2012 г., 0:13:29 UTC+2 пользователь Oleg Kiriltsev написал:

Oleg Kiriltsev

unread,
May 24, 2012, 9:16:40 AM5/24/12
to scala...@googlegroups.com
Hi,

do anybody have a idea / suggestion!? Or is not clear what is meant!?

best regards

Oleg

Ryan Bair

unread,
May 24, 2012, 9:56:18 AM5/24/12
to scala...@googlegroups.com
As far as I know this is not possible. You would have to do a query of t22 for each row of t11 or a join and then roll up the results.

I believe this situation was discussed in a presentation for the next version but I'm not sure what the status of that piece is.
Message has been deleted

Oleg Kiriltsev

unread,
May 24, 2012, 10:19:11 AM5/24/12
to scala...@googlegroups.com
ok, thanks.
possible solution:
query for table t1, result as list through and for each data record from t1 create query to table t2 or do you know better way !?
...
r = for {
t <- T1 ...
}. list

for(t <- r ) {
t.list_oft2 = for {
t2 <- T2 if t2.c = t.c 
}.list
}

... about. Or!?

best regards

Oleg

On Thursday, May 24, 2012 3:56:18 PM UTC+2, Ryan Bair wrote:
As far as I know this is not possible. You would have to do a query of t22 for each row of t11 or a join and then roll up the results.

I believe this situation was discussed in a presentation for the next version but I'm not sure what the status of that piece is.

Reply all
Reply to author
Forward
0 new messages