Skip to content

Instantly share code, notes, and snippets.

@tony-o
Created December 21, 2016 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tony-o/d19c6ab194370eb1872af5369d8e62ef to your computer and use it in GitHub Desktop.
Save tony-o/d19c6ab194370eb1872af5369d8e62ef to your computer and use it in GitHub Desktop.
my $prof = $orm.search('nickl', {
'-join' => {
'-table' => 'profile',
'-type' => 'inner',
'-on' => {
'uid' => 'id',
},
}
});
@Xliff
Copy link

Xliff commented Dec 21, 2016

Looks comprehensive enough. Although for your -on you might have more complex situations.

Consider:

my $prof = $orm.search('nickl', {
  '-join' => {
    '-table' => 'profile',
    '-type'  => 'inner',
    '-on' => {
      '-and' => [
         'uid' => 'id',
         'type' => 'admin'
     ]
    },
  }
});

@Xliff
Copy link

Xliff commented Dec 21, 2016

Tony-o,

Given your example in the docs, you have the following:

my @users = $orm.search('user', { #user table will be our main table
  '-join' => {
    '-table' => 'profile', #join the profile table to user
    '-type'  => 'inner',   #user an inner join, the default is 'left outer'
    '-on'    => {
      '-and' => {
        'uid' => 'DBORMID', #these are autoquoted where the key from the pair is quoted for the joining table and the value is quoted for the main table
                            #you can also use things like a pair here, ie: ('-lt' => 'some other column in user table')
      }
    }
  },
  '"profile"."name"' => ('-ne' => ''), #normal 'where' parameters, notice that quoting the table and field name for the joined table *may* be necessary
}).all;

That looks a little confusing because the way I am resolving the on part is"

INNER JOIN profile ON uid='DBORMID' AND 

Which doesn't make sense. Am I missing something?

@tony-o
Copy link
Author

tony-o commented Dec 22, 2016

@Xliff - yea so the way that the internals work on that is that it translates 'uid' => 'DBORMID' to profile.uid and user.DBORMID, respectively. So, it always takes the .key to be the table to be joined, and the .value for the parent table.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment