[Dbix-class] How do I determine whether a column name is valid?
Christopher H. Laco
claco at chrislaco.com
Sun Nov 5 23:50:45 GMT 2006
Josef Karthauser wrote:
> On Sun, Nov 05, 2006 at 02:52:24PM -0500, Christopher H. Laco wrote:
>>> So, the value of order_by can be something like 'domainname' or
>>> 'owner.username'.
>>>
>>> How do I check with D::C whether the column exists before feeding it to
>>> search, which expects it to exist? I've scanned loads of manual pages,
>>> but can't find anything relevant.
>>>
>> http://search.cpan.org/~blblack/DBIx-Class-0.07999_01/lib/DBIx/Class/Res=
ultSource.pm#has_column
>>
>> model('Domain')->result_source->has_column('foo');
>>
> =
> I saw that, but it doesn't work for related columns, like 'owner.username'
> below,
> =
> package Domain;
> use base qw/DBIx::Class/;
> =
> __PACKAGE__->load_components(qw/ PK::Auto Core /);
> __PACKAGE__->table('domain');
> __PACKAGE__->add_columns(qw/
> domainid domainname owner
> /);
> __PACKAGE__->set_primary_key('domainid');
> __PACKAGE__->belongs_to(owner =3D> 'Owner');
> =
> Is there a sensible way I should approach achieving that knowledge?
> =
> Joe.
('Domain')->related_resultset('Owner')->result_source->has_column('foo')...
Of course, if you're working with the schema object itself...
$schema->source('Owner')->has_column
-=3DChris
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: OpenPGP digital signature
Url : http://jules.scsys.co.uk/pipermail/dbix-class/attachments/20061105/d1=
716859/signature.pgp
More information about the Dbix-class
mailing list