[Jifty-commit] r5419 - in Net-Jifty: .
Jifty commits
jifty-commit at lists.jifty.org
Thu May 8 01:18:12 EDT 2008
Author: sartak
Date: Thu May 8 01:18:11 2008
New Revision: 5419
Modified:
Net-Jifty/ (props changed)
Net-Jifty/lib/Net/Jifty.pm
Log:
r55422 at onn: sartak | 2008-05-08 01:17:50 -0400
Try to break refers_to-style attributes into two (not quite there yet)
Modified: Net-Jifty/lib/Net/Jifty.pm
==============================================================================
--- Net-Jifty/lib/Net/Jifty.pm (original)
+++ Net-Jifty/lib/Net/Jifty.pm Thu May 8 01:18:11 2008
@@ -1007,6 +1007,9 @@
my $spec = $model_spec->{$column};
my %opts;
+ # the key name. this may be different for refers columns
+ $opts{init_arg} = $column;
+
$opts{is} = $spec->{readable} && $spec->{writable} ? 'rw'
: $spec->{readable} ? 'ro'
: undef;
@@ -1016,19 +1019,29 @@
$opts{required} = $spec->{mandatory};
if ($spec->{refers_to}) {
+ my %refer_opts;
$spec->{by} ||= 'id';
- $opts{lazy} = 1;
- $opts{isa} = $spec->{refers_to};
+ # end up with column=owner_id and refer_name=owner
+ $column =~ s/_id$//;
+ my $refer_name = $column;
+ $column .= $spec->{by};
+
+ $refer_opts{lazy} = 1;
+ $refer_opts{isa} = $spec->{refers_to};
+ my ($refer_class, $refer_by) = ($opts{isa}, $spec->{by});
- my ($refer_class, $refer_column) = ($opts{isa}, $spec->{by});
- $opts{default} = sub {
+ $refer_opts{default} = sub {
my $self = shift;
my $class = $self->_interface->create_model_class($refer_class);
+
+ # get the scalar referral value (probably the numeric ID)
my $attr = $self->meta->get_attribute($column);
my $value = $attr->get_read_method_ref->($self);
- $class->load($self->_interface, $refer_column, $value);
+
+ $class->load($self->_interface, $refer_by, $value);
};
+ push @attributes, Moose::Meta::Attribute->new($refer_name, %refer_opts);
}
push @attributes, Moose::Meta::Attribute->new($column, %opts);
More information about the Jifty-commit
mailing list