How to join two RT tables in perl?

'Aloha!

In my standalone program I would like to do a join on the tables
Transactions and Users in order to add Users.Name to my print
out. (and not just the user number)

But I somehow lost track while trying to figure out how it is done
in the RT code itself.

Below is a boiled down demo program which fails in the second
last line, which is somehow expected.

RT::Transaction::Name Unimplemented in main. (./Join-demo-2 line 31)

Perhaps somebody can help me in the right direction.

/Morten %-)

#!/usr/bin/perl

package RT;
our $DatabaseType = ‘mysql’;
our $DatabaseUser = ‘rtuser’;
our $DatabasePassword = ‘wibble’;
our $DatabaseName = ‘rtdb’;

package main;
use strict;
use warnings;
use lib ‘/usr/share/request-tracker3.6/lib’;
use RT;
use RT::Transactions;

RT::Init();
my $CurrentUser = RT::CurrentUser->new(‘cust-12345’);

my $t = new RT::Transactions($CurrentUser);
$t->LimitToTicket(1);

my $u = $t->NewAlias(‘Users’);
$t->Join(ALIAS1 => ‘main’,
FIELD1 => ‘Creator’,
ALIAS2 => $u,
FIELD2 => ‘id’);

while (my $row = $t->Next)
{
printf “id:%s, CreatorId:%s, Name:%s\n”, $row->id, $row->Creator,
$row->Name;
}

use
$row->CreatorObj->Name;

as far as I can see you don’t need join which is for limits, not for access.On Mon, May 5, 2008 at 5:09 PM, Morten Guldager morten.guldager@gmail.com wrote:

'Aloha!

In my standalone program I would like to do a join on the tables
Transactions and Users in order to add Users.Name to my print
out. (and not just the user number)

But I somehow lost track while trying to figure out how it is done
in the RT code itself.

Below is a boiled down demo program which fails in the second
last line, which is somehow expected.

RT::Transaction::Name Unimplemented in main. (./Join-demo-2 line 31)

Perhaps somebody can help me in the right direction.


/Morten %-)

#!/usr/bin/perl

package RT;
our $DatabaseType = ‘mysql’;
our $DatabaseUser = ‘rtuser’;
our $DatabasePassword = ‘wibble’;
our $DatabaseName = ‘rtdb’;

package main;
use strict;
use warnings;
use lib ‘/usr/share/request-tracker3.6/lib’;
use RT;
use RT::Transactions;

RT::Init();
my $CurrentUser = RT::CurrentUser->new(‘cust-12345’);

my $t = new RT::Transactions($CurrentUser);
$t->LimitToTicket(1);

my $u = $t->NewAlias(‘Users’);
$t->Join(ALIAS1 => ‘main’,
FIELD1 => ‘Creator’,
ALIAS2 => $u,
FIELD2 => ‘id’);

while (my $row = $t->Next)
{
printf “id:%s, CreatorId:%s, Name:%s\n”, $row->id, $row->Creator,
$row->Name;
}


The rt-users Archives

Community help: http://wiki.bestpractical.com
Commercial support: sales@bestpractical.com

Discover RT’s hidden secrets with RT Essentials from O’Reilly Media.
Buy a copy at http://rtbook.bestpractical.com

Best regards, Ruslan.

Ah thanks, works very well on the Creator column.

But it does not work on OldValue and NewValue. They change
type of content all the time. And some times they even contains
real data.

Which piece of secret magic do I need this time?

/Morten %-)On Mon, May 5, 2008 at 3:19 PM, Ruslan Zakirov ruz@bestpractical.com wrote:

use
$row->CreatorObj->Name;

as far as I can see you don’t need join which is for limits, not for
access.

On Mon, May 5, 2008 at 5:09 PM, Morten Guldager morten.guldager@gmail.com wrote:

'Aloha!

In my standalone program I would like to do a join on the tables
Transactions and Users in order to add Users.Name to my print
out. (and not just the user number)

But I somehow lost track while trying to figure out how it is done
in the RT code itself.

Below is a boiled down demo program which fails in the second
last line, which is somehow expected.

RT::Transaction::Name Unimplemented in main. (./Join-demo-2 line 31)

Perhaps somebody can help me in the right direction.


/Morten %-)

#!/usr/bin/perl

package RT;
our $DatabaseType = ‘mysql’;
our $DatabaseUser = ‘rtuser’;
our $DatabasePassword = ‘wibble’;
our $DatabaseName = ‘rtdb’;

package main;
use strict;
use warnings;
use lib ‘/usr/share/request-tracker3.6/lib’;
use RT;
use RT::Transactions;

RT::Init();
my $CurrentUser = RT::CurrentUser->new(‘cust-12345’);

my $t = new RT::Transactions($CurrentUser);
$t->LimitToTicket(1);

my $u = $t->NewAlias(‘Users’);
$t->Join(ALIAS1 => ‘main’,
FIELD1 => ‘Creator’,
ALIAS2 => $u,
FIELD2 => ‘id’);

while (my $row = $t->Next)
{
printf “id:%s, CreatorId:%s, Name:%s\n”, $row->id, $row->Creator,
$row->Name;
}


The rt-users Archives

Community help: http://wiki.bestpractical.com
Commercial support: sales@bestpractical.com

Discover RT’s hidden secrets with RT Essentials from O’Reilly Media.
Buy a copy at http://rtbook.bestpractical.com

Depends on what you want to do?On Mon, May 5, 2008 at 11:55 PM, Morten Guldager morten.guldager@gmail.com wrote:

Ah thanks, works very well on the Creator column.

But it does not work on OldValue and NewValue. They change
type of content all the time. And some times they even contains
real data.

Which piece of secret magic do I need this time?

/Morten %-)

On Mon, May 5, 2008 at 3:19 PM, Ruslan Zakirov ruz@bestpractical.com wrote:

use
$row->CreatorObj->Name;

as far as I can see you don’t need join which is for limits, not for
access.

On Mon, May 5, 2008 at 5:09 PM, Morten Guldager morten.guldager@gmail.com wrote:

'Aloha!

In my standalone program I would like to do a join on the tables
Transactions and Users in order to add Users.Name to my print
out. (and not just the user number)

But I somehow lost track while trying to figure out how it is done
in the RT code itself.

Below is a boiled down demo program which fails in the second
last line, which is somehow expected.

RT::Transaction::Name Unimplemented in main. (./Join-demo-2 line 31)

Perhaps somebody can help me in the right direction.


/Morten %-)

#!/usr/bin/perl

package RT;
our $DatabaseType = ‘mysql’;
our $DatabaseUser = ‘rtuser’;
our $DatabasePassword = ‘wibble’;
our $DatabaseName = ‘rtdb’;

package main;
use strict;
use warnings;
use lib ‘/usr/share/request-tracker3.6/lib’;
use RT;
use RT::Transactions;

RT::Init();
my $CurrentUser = RT::CurrentUser->new(‘cust-12345’);

my $t = new RT::Transactions($CurrentUser);
$t->LimitToTicket(1);

my $u = $t->NewAlias(‘Users’);
$t->Join(ALIAS1 => ‘main’,
FIELD1 => ‘Creator’,
ALIAS2 => $u,
FIELD2 => ‘id’);

while (my $row = $t->Next)
{
printf “id:%s, CreatorId:%s, Name:%s\n”, $row->id, $row->Creator,
$row->Name;
}


The rt-users Archives

Community help: http://wiki.bestpractical.com
Commercial support: sales@bestpractical.com

Discover RT’s hidden secrets with RT Essentials from O’Reilly Media.
Buy a copy at http://rtbook.bestpractical.com

Best regards, Ruslan.