Message from discussion
How do I access the fields of a link-table with Lift Mapper?
Received: by 10.66.86.39 with SMTP id m7mr509995paz.4.1349988520122;
Thu, 11 Oct 2012 13:48:40 -0700 (PDT)
X-BeenThere: liftweb@googlegroups.com
Received: by 10.68.197.72 with SMTP id is8ls7896424pbc.5.gmail; Thu, 11 Oct
2012 13:48:35 -0700 (PDT)
Received: by 10.68.226.41 with SMTP id rp9mr602286pbc.4.1349988515690;
Thu, 11 Oct 2012 13:48:35 -0700 (PDT)
Received: by 10.68.226.41 with SMTP id rp9mr602285pbc.4.1349988515678;
Thu, 11 Oct 2012 13:48:35 -0700 (PDT)
Return-Path: <fmpwiz...@gmail.com>
Received: from mail-pb0-f48.google.com (mail-pb0-f48.google.com [209.85.160.48])
by gmr-mx.google.com with ESMTPS id g4si1489191pax.1.2012.10.11.13.48.35
(version=TLSv1/SSLv3 cipher=OTHER);
Thu, 11 Oct 2012 13:48:35 -0700 (PDT)
Received-SPF: pass (google.com: domain of fmpwiz...@gmail.com designates 209.85.160.48 as permitted sender) client-ip=209.85.160.48;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of fmpwiz...@gmail.com designates 209.85.160.48 as permitted sender) smtp.mail=fmpwiz...@gmail.com; dkim=pass header...@gmail.com
Received: by mail-pb0-f48.google.com with SMTP id wy7so2341994pbc.21
for <liftweb@googlegroups.com>; Thu, 11 Oct 2012 13:48:35 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20120113;
h=mime-version:sender:in-reply-to:references:date
:x-google-sender-auth:message-id:subject:from:to:content-type;
bh=2zd5BKb2mz6VA26zAM3AJzWsrUyUzJzT6GWdbRYiGL0=;
b=OWCkHIWxR9WIkWa6S3yXQ/B+aZkt1k4psLB9W0Vq/hMa4lmYIvZKMwogx7eF0sfpnk
lIRJfCXBEWsst3TTX5++Um3vOyy9awWAPUvrqaqhmzjGculv2fdQueNivFi1rUQVLfBc
4dxiokNWQ8XZrMx75+9R/yinssACnNmpGGmauGmuuGrbZbDIjzxJlh4cRVbdCxjg8EFv
qEuHzpiGU5oQEkkO4C8fy3z1oxi9zuw41uSqwBTy1pYNtx4CqyzLG/Z1T93+e8jVWn24
5pMStO5fKwzFV+nRkJS51s/xzsJiiNpBJwB3oD0Ix2aI1b42rXp5siHFZuiiPzHj2LB0
iNdQ==
MIME-Version: 1.0
Received: by 10.68.134.37 with SMTP id ph5mr7292546pbb.41.1349988514997; Thu,
11 Oct 2012 13:48:34 -0700 (PDT)
Sender: fmpwiz...@gmail.com
Received: by 10.66.193.7 with HTTP; Thu, 11 Oct 2012 13:48:34 -0700 (PDT)
In-Reply-To: <1eeebae0-defe-4b56-8061-2dc9b1380679@googlegroups.com>
References: <6f69c99d-1f39-48b0-a548-cabbf4857138@googlegroups.com>
<CAE-RkXi-bqF1b_VDAQ_jWHZjDu8ARDhKx6mxO=ZPvJo8GJn...@mail.gmail.com>
<1eeebae0-defe-4b56-8061-2dc9b1380679@googlegroups.com>
Date: Thu, 11 Oct 2012 16:48:34 -0400
Message-ID: <CAE-RkXjiLWVRn+SgFPZNQNZAiDQBpY67j6y4wL9Aqrr74Xi...@mail.gmail.com>
Subject: Re: [Lift] How do I access the fields of a link-table with Lift Mapper?
From: Diego Medina <di...@fmpwizard.com>
To: liftweb@googlegroups.com
Content-Type: text/plain; charset=ISO-8859-1
ok, so, from where do you want to access the fields in
AssignmentformLink? What is your starting point?
Thanks
Diego
On Thu, Oct 11, 2012 at 4:27 PM, Jacobus <jacobusreyn...@gmail.com> wrote:
> Hi,
>
> Thanks for the advice and link. The mapping as I have described it does
> work, but I don't know how to get to the link-table's fields. It must be
> possible.... I hope :-p
>
> Kind regards,
> Jacobus
>
>
> On Thursday, 11 October 2012 21:00:34 UTC+2, fmpwizard wrote:
>>
>> Hi, You don;t have your ManyToMany relationship defined right (or
>> maybe I'm missing something)
>>
>> from here:
>>
>>
>> class Assignment extends LongKeyedMapper[Assignment] with IdPK with
>> ManyToMany {
>> def getSingleton = Assignment
>>
>> object id_parent extends MappedLong(this)
>>
>> object label extends MappedString(this, 40)
>>
>> object order extends MappedInt(this)
>>
>> object guard extends MappedString(this, 200)
>>
>> object forms extends MappedManyToMany(
>> AssignmentformLink, AssignmentformLink.assignment,
>> AssignmentformLink.form, TForm
>> )
>>
>> }
>>
>>
>>
>> these lines
>>
>> object forms extends MappedManyToMany(
>> AssignmentformLink, AssignmentformLink.assignment,
>> AssignmentformLink.form, TForm
>> )
>>
>> one of the two tables there should the the class enclosing the object
>> forms, maybe, in SQL, how are your tables related, so I can better
>> help you, also, you may want to look at this wiki page (which I find
>> very useful), about mapper and manyTOMany:
>>
>>
>> https://www.assembla.com/spaces/liftweb/wiki/mapper#manytomany
>>
>>
>> Thanks
>>
>> Diego
>>
>>
>> On Thu, Oct 11, 2012 at 2:33 PM, Jacobus <jacobus...@gmail.com> wrote:
>> > Hi there,
>> >
>> > I've asked this question on stack-overflow
>> > (http://stackoverflow.com/q/12843590/828757). I hope the lift forum will
>> > be
>> > able to give me some guidance:
>> >
>> > From the Lift-Web Mapper model below, how do I access the fields under
>> > AssignmentformLink?
>> >
>> > object TForm extends TForm with LongKeyedMetaMapper[TForm]
>> >
>> > class TForm extends LongKeyedMapper[TForm] with IdPK with ManyToMany
>> > {
>> > def getSingleton = TForm
>> >
>> > object label extends MappedString(this, 40)
>> >
>> > object pattern extends MappedString(this, 200)
>> >
>> > object assignments extends MappedManyToMany(
>> > AssignmentformLink, AssignmentformLink.assignment,
>> > AssignmentformLink.form, TForm)
>> >
>> > }
>> >
>> > object AssignmentformLink extends AssignmentformLink with
>> > LongKeyedMetaMapper[AssignmentformLink] {
>> > override def dbIndexes = Index(form, assignment) ::
>> > super.dbIndexes
>> > }
>> >
>> > class AssignmentformLink extends LongKeyedMapper[AssignmentformLink]
>> > with IdPK {
>> > def getSingleton = AssignmentformLink
>> >
>> > object form extends MappedLongForeignKey(this, TForm)
>> >
>> > object assignment extends MappedLongForeignKey(this, Assignment)
>> >
>> > object order extends MappedInt(this)
>> >
>> > object readonly extends MappedBoolean(this)
>> >
>> > object required extends MappedBoolean(this)
>> >
>> > object visible extends MappedBoolean(this)
>> >
>> > }
>> >
>> > object Assignment extends Assignment with
>> > LongKeyedMetaMapper[Assignment]
>> >
>> > class Assignment extends LongKeyedMapper[Assignment] with IdPK with
>> > ManyToMany {
>> > def getSingleton = Assignment
>> >
>> > object id_parent extends MappedLong(this)
>> >
>> > object label extends MappedString(this, 40)
>> >
>> > object order extends MappedInt(this)
>> >
>> > object guard extends MappedString(this, 200)
>> >
>> > object forms extends MappedManyToMany(
>> > AssignmentformLink, AssignmentformLink.assignment,
>> > AssignmentformLink.form, TForm)
>> >
>> > }
>> >
>> > To get an assignmet and the forms linked to it, you do this:
>> >
>> > val assignments = Assignments.find(By(Assignment.id, 123))
>> >
>> > assignments match {
>> > case Full(as) => {
>> > val forms = as.forms
>> > .....
>> >
>> > But I have no idea how to navigate to the `order, readonly, required...`
>> > fields under `AssignmentformLink`.
>> >
>> > I realise I can search for the link manually, ie.
>> > `AssignmentformLink.find(By(form...),By(assignment...))`, but this will
>> > result in inefficient code and really misses the point of using objects.
>> >
>> > I need to be able to *navigate* from the form to the link table's
>> > fields.
>> >
>> > Kind regards,
>> > Jacobus
>> >
>> > --
>> > --
>> > Lift, the simply functional web framework: http://liftweb.net
>> > Code: http://github.com/lift
>> > Discussion: http://groups.google.com/group/liftweb
>> > Stuck? Help us help you:
>> > https://www.assembla.com/wiki/show/liftweb/Posting_example_code
>> >
>> >
>> >
>>
>>
>>
>> --
>> Diego Medina
>> Lift/Scala Developer
>> di...@fmpwizard.com
>> http://www.fmpwizard.com
>
> --
> --
> Lift, the simply functional web framework: http://liftweb.net
> Code: http://github.com/lift
> Discussion: http://groups.google.com/group/liftweb
> Stuck? Help us help you:
> https://www.assembla.com/wiki/show/liftweb/Posting_example_code
>
>
>
--
Diego Medina
Lift/Scala Developer
di...@fmpwizard.com
http://www.fmpwizard.com