package SQL::Translator::Producer::Turnkey;
# -------------------------------------------------------------------
-# $Id: Turnkey.pm,v 1.9 2003-10-15 16:48:39 kycl4rk Exp $
+# $Id: Turnkey.pm,v 1.10 2003-12-28 12:14:59 boconnor Exp $
# -------------------------------------------------------------------
# Copyright (C) 2003 Allen Day <allenday@ucla.edu>,
# Brian O'Connor <brian.oconnor@excite.com>.
use strict;
use vars qw[ $VERSION $DEBUG ];
-$VERSION = sprintf "%d.%02d", q$Revision: 1.9 $ =~ /(\d+)\.(\d+)/;
+$VERSION = sprintf "%d.%02d", q$Revision: 1.10 $ =~ /(\d+)\.(\d+)/;
$DEBUG = 1 unless defined $DEBUG;
use SQL::Translator::Schema::Constants;
}
}
}
-
$meta{"nodes"} = $graph->node;
return(translateForm($t, \%meta));
}
sub translateForm {
my $t = shift;
my $meta = shift;
+
+
+#print "Node Data:\n";
+#print Dumper $meta->{nodes};
+#exit;
+
my $args = $t->producer_args;
my $type = $meta->{'template'};
my $tt2;
# Here documents for the tt2 templates #
###########################################
- if($type eq 'classdbi'){
+ if($type eq 'dbi'){
return <<EOF;
+
+# MACRO
+
[% MACRO printPackage(node) BLOCK %]
# --------------------------------------------
[% #printHasFriendly(node) %]
[% END %]
+# MACRO
+
[% MACRO printPKAccessors(array, name) BLOCK %]
#
# Primary key accessors
[% FOREACH edge = edges %]
[% IF edge.type == 'export' %]
-[% node.name %]->has_many([% edge.thatnode.table.name %]_[% edge.thatfield.name %], '[% edge.thatnode.name %]' => '[% edge.thatfield.name %]');
+[% node.name %]->has_many('[% edge.thatnode.table.name %]_[% edge.thatfield.name %]', '[% edge.thatnode.name %]' => '[% edge.thatfield.name %]');
[% IF node.via(edge.thatnode.name) >= 1 %]
sub [% edge.thatnode.table.name %]_[% format_fk(edge.thatnode.table.name,edge.thatfield.name) %]s { return shift->[% edge.thatnode.table.name %]_[% edge.thatfield.name %] }
[% ELSIF edge.thatnode.table.is_data %]
#
# Has Friendly
#
-hello, sailor!
+
[% END %]
[% MACRO printList(array) BLOCK %][% FOREACH item = array %][% item %] [% END %][% END %]
[% printPackage(node.value) %]
[% END %]
EOF
+}
+
+
+elsif($type eq 'atom'){
-} elsif($type eq 'atom'){
return <<'EOF';
[% ###### DOCUMENT START ###### %]
-[% FOREACH node = linkable %]
+[% FOREACH node = nodes %]
+[% IF node.value.compoundedges %]
##############################################
-package Durian::Atom::[% node.key FILTER ucfirst %];
+package Turnkey::Atom::[% node.value.name FILTER replace "Turnkey::Model::", "" %];
-[% pname = node.key FILTER ucfirst%]
-[% pkey = "Durian::Model::${pname}" %]
+[% pname = node.value.name FILTER replace "Turnkey::Model::", "" %]
+[% pkey = "Turnkey::Model::${pname}" %]
-use base qw(Durian::Atom);
+use base qw(Turnkey::Atom);
use Data::Dumper;
sub can_render {
my $dbobject = shift;
# Assumption here that if it's not rendering on it's own dbobject
# then it's a list. This will be updated when AtomLists are implemented -boconnor
- if(ref($dbobject) eq 'Durian::Model::[% node.key FILTER ucfirst %]') {
+ if(ref($dbobject) eq 'Turnkey::Model::[% pname %]') {
return(_render_record($dbobject));
}
else { return(_render_list($dbobject)); }
my @output = ();
my $row = {};
my $field_hash = {};
- [% FOREACH field = nodes.$pkey.columns_essential %]
- $field_hash->{[% field %]} = $dbobject->[% field %]();
+ [% FOREACH value = node.value.data_fields %]
+ [% IF value != 1 %]
+ $field_hash->{[% value %]} = $dbobject->[% value %]();
+ [% END %]
[% END %]
$row->{data} = $field_hash;
$row->{id} = $dbobject->id();
{
my $row = {};
my $field_hash = {};
- [% FOREACH field = nodes.$pkey.columns_essential %]
- $field_hash->{[% field %]} = $object->[% field %]();
- [% END %]
+ [% FOREACH value = node.value.data_fields %]
+ [% IF value != 1 %]
+ $field_hash->{[% value %]} = $object->[% value %]();
+ [% END %]
+ [% END %]
$row->{data} = $field_hash;
$row->{id} = $object->id();
push @output, $row;
}
1;
-
+[% END %]
[% END %]
EOF
$self->node_push($table->name => $node);
+ if ($table->is_trivial_link) { $node->is_trivial_link(1); }
+ else { $node->is_trivial_link(0); }
+
$node->order($self->order_incr());
$node->name( $self->translator->format_package_name($table->name) );
$node->base( $self->baseclass );
foreach my $node ($self->node_values){
foreach my $field ($node->table->get_fields){
- next unless $field->is_foreign_key;
-
+ if (!$field->is_foreign_key && !$field->is_primary_key) { $node->data_fields->{$field->name} = 1; }
+ elsif($field->is_foreign_key) {
my $that = $self->node($field->foreign_key_reference->reference_table);
#this means we have an incomplete schema
warn $node->name . "\t" . $that->edgecount($node->name);
$node->push_edges( $edge );
$that->push_edges( $edge->flip );
+ }
}
}