[Dbix-class] Relationship to serve internationalization
vti
mbit at ukr.net
Tue Nov 21 20:39:46 GMT 2006
we have two tables
one is for original language
==================
package DB::Ministries;
use base 'DBIx::Class';
__PACKAGE__->load_components( qw/ PK::Auto Core / );
__PACKAGE__->table( 'ministries' );
__PACKAGE__->add_columns( qw/ ministryid
lang
content
/ );
__PACKAGE__->set_primary_key(qw/ministryid/);
==================
the second one is for translations
==================
package DB::MinistriesI18N;
use base 'DBIx::Class';
__PACKAGE__->load_components( qw/ PK::Auto Core / );
; __PACKAGE__->table( 'ministries_i18n' )
; __PACKAGE__->add_columns( qw/ i18nid ministryid
lang
content
/
)
; __PACKAGE__->set_primary_key( qw/ i18nid / )
; __PACKAGE__->belongs_to( 'ministryid' => 'DB::Ministries' )
==================
so we have to decide what relationship is between original and i18n
version, i tried
__PACKAGE__->might_have( 'ru' => 'DB::MinistriesI18N'
, { 'foreign.lang' => 'ru'
, 'foreign.ministryid' => 'self.ministryid'
}
, { acessor => 'single' }
);
but probably it is not right, besause it complains about 'foreign.lang' =>
'ru'
when i used Class::DBI i wrote my own relationship, but in DBIC i found
different method, such as writing condition while writing relationship
what i want to get is:
ministry.ru.title gives me title from i18n, while ministry.title gives the
original one
i would be appreciate if someone could show the way where i should search,
read or understand
thanks anyway
More information about the Dbix-class
mailing list