Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7447661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:41:03+00:00 2026-05-29T12:41:03+00:00

I would like to know if there is a way to do some complex

  • 0

I would like to know if there is a way to do some complex SQL queries using Mapper in Liftweb.

In fact what I would like to do is to perform a Join query from databases Employes and Departments using the fact that they are linked by a 1-to-many relationship.
Another example is also welcome.

Thanks in advance.


Here are some more details: Suppose I have 2 tables :

Employee : birthday, department ID, salary
Department : department ID, budget, address

Now I would like to obtain a list of the object Employee (created with Mapper) which have a salary > 10$ and a department budget < 100$.

Of course my original code is much more complicated than that but my objective is to be able to have a List of mapped objects (ie Employee) corresponding to criterions in its own table or on a linked table.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T12:41:04+00:00Added an answer on May 29, 2026 at 12:41 pm

    I’ve looked this up. It looks as though the joins are done in the object layer.

    Extrapolated from http://exploring.liftweb.net/master/index-8.html to your case:

    // Accessing foreign objects  
    class Employee extends LongKeyedMapper[Employee] with IdPK {  
     ...  
      object department extends MappedLongForeignKey(this, Department)  
      def departmentName =  
        Text("My department is " + (department.obj.map(_.name.is) openOr "Unknown"))  
    }  
    
    class Department ... {  
      ...  
      def entries = Employee.findAll(By(Employee.department, this.id))  
    }  
    

    If you want to do many-to-many mappings you’ll need to provide your own
    “join” class with foreign keys to both of your mapped entities.

    // DepartmentId Entity  
    class DepartmentId extends LongKeyedMapper[DepartmentId] with IdPK {  
      def getSingleton = DepartmentId  
      object name extends MappedString(this,100)  
    }  
    object DepartmentId extends DepartmentId with LongKeyedMetaMapper[DepartmentId] {  
      override def fieldOrder = List(name)  
    }  
    

    Next, we define our join entity, as shown below.
    It’s a LongKeyedMapper just like the rest of the entities,
    but it only contains foreign key fields to the other entities.

    // Join Entity  
    class DepartmentIdTag extends LongKeyedMapper[DepartmentIdTag] with IdPK {  
      def getSingleton = DepartmentIdTag  
      object departmentid extends MappedLongForeignKey(this,DepartmentId)  
      object Employee extends MappedLongForeignKey(this,Employee)  
    }  
    object DepartmentIdTag extends DepartmentIdTag with LongKeyedMetaMapper[DepartmentIdTag] {  
      def join (departmentid : DepartmentId, tx : Employee) =  
        this.create.departmentid(departmentid).Employee(tx).save  
    }  
    

    To use the join entity, you’ll need to create a new instance and set the
    appropriate foreign keys to point to the associated instances. As you can see,
    we’ve defined a convenience method on our Expense meta object to do just that.
    To make the many-to-many accessible as a field on our entities, we can use the
    HasManyThrough trait, as shown below

    // HasManyThrough for Many-to-Many Relationships  
    class Employee ... {  
      object departmentids extends HasManyThrough(this, DepartmentId,   
        DepartmentIdTag, DepartmentIdTag.departmentid, DepartmentIdTag.Employee)  
    }  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know if there is some way to share a variable
I'm implementing some code generators, i would like to know if there's any way
I would like to know if there is any way to add custom behaviour
I would like to know if there is a way to disable automatic loading
I would like to know if there is a way to keep the session
I would like to know if there is any way I can apply 100%
I would like to know if there is any way to return an char
I would like to know if there is a way to take create a
I would like to know if there is any way that I could build
I would like to know if there is a way to test whenever thread

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.