On 5/25/06, Jonathan Vanasco <[EMAIL PROTECTED]> wrote:
i have the 2 packages below
Asset
AssetType
Asset is basically
name
id
type_id
where type_id is a fkey to another table
when i pull a record for Asset or join onto asset from another table,
i need to get the asset_type_id name
sometimes i pull a record for something that is linked to Asset - so
i'll need to delve 2 tables down
That's not a problem. In fact, you can go as deep as you like, either
in a single query or in a series of individual queries. Are you
calling load() or using the Manager to get the Asset object? Post
some code samples that show what you'll like to do and I can describe
how to do it.
package MyApp::RoseDB::Asset;
use base qw(Rose::DB::Object);
use MyApp::RoseDB;
__PACKAGE__->meta->table('asset');
__PACKAGE__->meta->columns(qw(id asset_type_id name));
__PACKAGE__->meta->primary_key_columns('id');
__PACKAGE__->meta->add_unique_key('name');
__PACKAGE__->meta->foreign_keys
(
asset_type =>
{
class => 'MyApp::RoseDB::AssetType',
key_columns => { asset_type_id => 'id' },
},
);
__PACKAGE__->meta->initialize( replace_existing => 1 );
sub init_db { MyApp::RoseDB->new }
Don't forget to use or require all related classes
(MyApp::RoseDB::AssetType in this case) from within the "parent"
class. Consider this code:
use MyApp::RoseDB::Asset;
$o = MyApp::RoseDB::Asset->new(...)->load;
# This will blow up if MyApp::RoseDB::AssetType is not loaded
$o->asset_type;
So, you can either require yourself to remember to load
MyApp::RoseDB::AssetType every time you load MyApp::RoseDB::Asset, or
you can just load MyApp::RoseDB::AssetType from within
MyApp::RoseDB::Asset. I recommend the latter.
(I also recommend that you inherit from your own custom base class
(where the "sub init_db { MyApp::RoseDB->new }" bit should be defined)
and not from Rose::DB::Object directly.)
-John
-------------------------------------------------------
All the advantages of Linux Managed Hosting--Without the Cost and Risk!
Fully trained technicians. The highest number of Red Hat certifications in
the hosting industry. Fanatical Support. Click to learn more
http://sel.as-us.falkag.net/sel?cmd=lnk&kid7521&bid$8729&dat1642
_______________________________________________
Rose-db-object mailing list
Rose-db-object@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rose-db-object