[Gmod-phendiver] [BCS] many to many relationship naming

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[Gmod-phendiver] [BCS] many to many relationship naming

Bob MacCallum
I was just going through methodically adding m2m relationships for the
NatDiv result classes and noticed that I'm naming the relationships
simply, like 'stocks', 'nd_protocols', 'nd_experiments' etc.

Then I look in Bio::Chado::Schema::Result::General::Dbxref and see
that they are all suffixed with _mm (e.g. stocks_mm).  I see why,
because for example $dbxref->stocks already exists for the one-to-many
(stock to dbxref) relationship, so _mm is needed to disambiguate.

I could do that too for the natdiv classes...  at least that would be
future proof in case one-to-many rels are added later.  What do people
prefer?

Or, is it possible (or indeed desirable) to have a $dbxref->stocks_all
method which returns both resultsets somehow magically appended
together?

------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network
management toolset available today.  Delivers lowest initial
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
Gmod-phendiver mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gmod-phendiver
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: [Gmod-phendiver] [BCS] many to many relationship naming

Bob MacCallum
Looking at the BCS code that existed before I started adding
many-to-many rels, there's a mix of _mm and non-suffixed relationship
names.
Obviously in cases like dbxref, we have to have two relations (e.g. to
stock) with different names.

However, the _mm suffix isn't a very good one.  From the dbxref's
point of view, it's a one to many relationship (to stocks, for
example).
It would be nice to change both names: e.g.

stocks -> stocks_as_primary
stocks_mm -> stocks_as_secondary
(other naming suggestions welcome, e.g. stocks_via_primary_dbxref,
even stocks_via_m2m, stocks_via_linker would be better, perhaps?)

but the former ('stocks') can't be changed because it's automatically generated.

If, hypothetically, we could rename both, then $dbxref->stocks could
return all stocks, thanks to some DBIx magic I just looked up:

sub stocks {
  my ($self) = @_;
  my $primary = $self->stocks_as_primary;
  my $secondary = $self->stocks_as_secondary;
  return $primary->union($secondary);
}

where a Stocks custom ResultSet (see Cvterm for an example of this) does
__PACKAGE__->load_components(qw{Helper::ResultSet::SetOperations});

(or call it stocks_as_primary_or_secondary)

However, as a convenience method, it would have limited utility where
people are interested in attributes of the linker table (e.g.
'is_current' for stocks).

For the natdiv module, and related objects, I think I'm going to add
m2ms without the _mm wherever possible, and NOT add any convenience
xxxxxs_as_primary_or_secondary methods.  I think we all want to keep
BCS fairly close to the db schema.  If people want convenience
methods, they can subclass the schema (like we have successfully
managed to do).

cheers,
Bob.

On Wed, May 4, 2011 at 11:49 PM, Bob MacCallum
<[hidden email]> wrote:

> I was just going through methodically adding m2m relationships for the
> NatDiv result classes and noticed that I'm naming the relationships
> simply, like 'stocks', 'nd_protocols', 'nd_experiments' etc.
>
> Then I look in Bio::Chado::Schema::Result::General::Dbxref and see
> that they are all suffixed with _mm (e.g. stocks_mm).  I see why,
> because for example $dbxref->stocks already exists for the one-to-many
> (stock to dbxref) relationship, so _mm is needed to disambiguate.
>
> I could do that too for the natdiv classes...  at least that would be
> future proof in case one-to-many rels are added later.  What do people
> prefer?
>
> Or, is it possible (or indeed desirable) to have a $dbxref->stocks_all
> method which returns both resultsets somehow magically appended
> together?
>

------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network
management toolset available today.  Delivers lowest initial
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
Gmod-phendiver mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/gmod-phendiver
Loading...