From: Mark Addison Date: Tue, 23 Mar 2004 21:26:55 +0000 (+0000) Subject: Added full_name. X-Git-Tag: v0.06~121 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4809213f4448732f4b75717164c717dd2d9bc7fe;p=dbsrgits%2FSQL-Translator.git Added full_name. --- diff --git a/lib/SQL/Translator/Schema/Field.pm b/lib/SQL/Translator/Schema/Field.pm index c574fb1..0773a44 100644 --- a/lib/SQL/Translator/Schema/Field.pm +++ b/lib/SQL/Translator/Schema/Field.pm @@ -1,7 +1,7 @@ package SQL::Translator::Schema::Field; # ---------------------------------------------------------------------- -# $Id: Field.pm,v 1.14 2004-03-23 21:05:19 grommit Exp $ +# $Id: Field.pm,v 1.15 2004-03-23 21:26:55 grommit Exp $ # ---------------------------------------------------------------------- # Copyright (C) 2002-4 SQLFairy Authors # @@ -50,7 +50,7 @@ use SQL::Translator::Utils 'parse_list_arg'; use base 'Class::Base'; use vars qw($VERSION $TABLE_COUNT $VIEW_COUNT); -$VERSION = sprintf "%d.%02d", q$Revision: 1.14 $ =~ /(\d+)\.(\d+)/; +$VERSION = sprintf "%d.%02d", q$Revision: 1.15 $ =~ /(\d+)\.(\d+)/; # Stringify to our name, being careful not to pass any args through so we don't # accidentally set it to undef. We also have to tweak bool so the object is @@ -450,6 +450,19 @@ Errors ("No field name") if you try to set a blank name. return $self->{'name'} || ''; } +sub full_name { + +=head2 full_name + +Read only method to return the fields name with its table name pre-pended. +e.g. "person.foo". + +=cut + + my $self = shift; + return $self->table.".".$self->name; +} + # ---------------------------------------------------------------------- sub order { diff --git a/t/13schema.t b/t/13schema.t index 40bf82c..e9050e5 100644 --- a/t/13schema.t +++ b/t/13schema.t @@ -4,7 +4,7 @@ $| = 1; use strict; -use Test::More tests => 196; +use Test::More tests => 197; use SQL::Translator::Schema::Constants; require_ok( 'SQL::Translator::Schema' ); @@ -98,6 +98,7 @@ require_ok( 'SQL::Translator::Schema' ); warn $person_table->error; isa_ok( $f1, 'SQL::Translator::Schema::Field', 'Field' ); is( $f1->name, 'foo', 'Field name is "foo"' ); + is( $f1->full_name, 'person.foo', 'Field full_name is "person.foo"' ); is( "$f1", 'foo', 'Field stringifies to "foo"' ); is( $f1->data_type, '', 'Field data type is blank' ); is( $f1->size, 0, 'Field size is "0"' );