[Dbix-class] Relationship::Base join-free exception question
Peter Rabbitson
rabbit+dbic at rabbit.us
Wed Jul 8 12:56:19 GMT 2015
-- resending as I misdirected my reply to the wrong list --
On 07/07/2015 11:41 PM, Marco Palma wrote:
> I'll be honest, it is not clear to my why, after having read that
> language in the docs, an exception must be thrown.
>
> "it may elect to additionally return a simplified
> *optional* join-free" reads to me as if the "join-free" part is
> optional, though the code definitely disagrees.
>
> The left of my relationship is my post class. Once a row object of this
> class is looked up, I can use it's auto-incrementing PK as the
> object_id, so it does seem to me that the right-side rows have FKs to
> use. Having commented out the exception, I am able to riff on
> variations of:
>
> my @comments = $self->storage
> ->resultset( 'post' )
> ->search({ author => 'marcopalma' })
> ->related_resultset( 'comments' )->all;
>
>
> without problem.
Correct, it *is* optional for this case.
It is *not* optional when you invoke new_related: You can not take a
what is essentially a "black-box condition" and deduce from it
definitively how to set object fields based on another object.
Perhaps the implementation in the latest versions makes it clearer:
https://metacpan.org/source/RIBASUSHI/DBIx-Class-0.082820/lib/DBIx/Class/Relationship/Base.pm#L677-683
Does this make more sense?
More information about the DBIx-Class
mailing list