[Dbix-class] some random relationship question
Benjamin Hitz
hitz at genome.stanford.edu
Thu Nov 29 00:03:32 GMT 2007
The first question is more of a SQL table design question than DBIC,
but it's at least related.
If I want a "might_have" relationship ( one-to-zero/one-to-one only),
how do I specify this in the table description? Or do you just
always do this like a one-to-many linking table, and enforce no > 1
row programatically or via DB trigger.
In a DBIC/Schema sense - my DBIx::Class::Schema::Loader reads the
linking table structure and sets up a ->has_many relationship.
Do I just override this with with a ->might_have or ->has_one
relationship (depending if you want outer or inner joins)?
Second question, more DBIC related - what is a good pragma for
getting out a single object when your DB specifies a one-to-many.
I find myself often constructing stuff like $myObjectIwant =
$resultSetICobbledTogether->next; (or ->first) just because I *know*
that there should be exactly 1 "row" in the result set (sometimes I
am using a search_related('belongs_to_rel').
Something like a find_related method (search_related but you specify
only PK)
Thanks,
Ben
--
Ben Hitz
Senior Scientific Programmer ** Saccharomyces Genome Database ** GO
Consortium
Stanford University ** hitz at genome.stanford.edu
More information about the DBIx-Class
mailing list