Hello again all,
I'm working on some generalized code, of which the following is an example case. I have the following structure in a hash (brought to you today by Data::Dumper):
'structure' => { 'groups' => { 'properties' => { 'groupid' => undef, 'grouptitle' => undef }, 'source' => 'user.groups' }, 'identity' => { 'properties' => { 'username' => unde +f, 'id' => undef }, 'source' => undef } },
And I have a SQL query that will retrieve the values for groupid,grouptitle,username and id. It may return one or many rows, but what I'd like to do is to take every record that comes through and stuff it into the above structure, and then pass a list of these hashrefs back to the calling code.
I've already got ideas on how to handle one-to-many relationships within records. Case in point is the 'groups' hashref. When i do a lookup on it's 'source' attribute, i get back that it has a toMany relationship with the primary key for this query (which in this case is 'id' ). So I know that the record structure i return will look like this:
{ 'groups' => [ { groupid=> '0', grouptitle=>'SysAdmins', }, { groupid=> '1', grouptitle=>'PerlGurus', } ] 'identity' => { username=> 'LWall', id=>1 } }
I intend to handle this by having the records stored in a hash (using the query's primary key for the hash's key), and an array of references to the hash entries to maintain order (important as the sql queries will often have Order By clauses). I'll then return either the array or a reference to that array to the calling code.
My question is how to get there from here. What would people suggest for the best approach for:
In reply to Building and returning structured records from a query by AidanLee
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |