[Dbix-class] SQL::Translator::Parser::DBIx::Class
Stephan Szabo
sszabo at megazone.bigpanda.com
Mon Mar 27 18:08:26 CEST 2006
On Mon, 27 Mar 2006, Matt S Trout wrote:
> Stephan Szabo wrote:
> > On Sun, 26 Mar 2006, Stephan Szabo wrote:
> >
> >> While playing with SQL::Translator to generate sql scripts from schemas, I
> >> noticed that the DBIx::Class parser seemed to grab only one column of
> >> multi-column relationships. It looks like just making it work across
> >> $rel_info->{cond} into an array rather than taking only the first key
> >> should work, something like:
> >>
> >> my @cond = keys(%{$rel_info->{cond}});
> >> my @keys = map {/^\w+\.(\w+)$/} @cond;
> >> my @refkeys = map {$rel_info->{cond}->{$_} =~ /^\w+\.(\w+)$/} @cond;
> >
> > And I should really actually cut and paste rather than doing it freehand
> > when I copy something into an email and/or check it before sending. The
> > above assignments are backwards (it should be refkeys in the first and
> > keys in the second).
> >
> >> if($rel_table)
> >> {
> >> $table->add_constraint(
> >> type => 'foreign_key',
> >> name => "fk_$keys[0]",
> >> fields => \@keys,
> >> reference_fields => \@refkeys,
> >> reference_table => $rel_table,
> >> );
> >> }
> >>
> >> Does that seem reasonable?
>
> Seems like a damn good start to me. If you grab svn and apply that tweak then
> get maint/gen-schema.pl to load the HelperRels stuff so it's got some
> relationships to work with and see what the SQLite file you end up with looks
> like?
Sadly, it looks like at least the version of the SQLite producer I have
ignores foreign key constraints (as even the existing relationships don't
seem to produce single column foreign keys). I'm working on seeing how
hard it'd be to try it against a different backend to see what gets
produced.
> Also note the bigass comment I left just above that section about what needs
> to produce an FK constraint and what doesn't :)
Yeah. :)
> (I'd apply this and clear it up myself but I don't think I'll have time next
> couple days, sorry - so have a play and tell the list how far you get and
> we'll see what we can do ...)
No problem, it was just the first time I'd played with innards of this
stuff, so I thought I should make sure I wasn't chasing geese.
More information about the Dbix-class
mailing list