[Dbix-class] Bug with relationships on new objects.

Jess Robinson castaway at desert-island.me.uk
Mon Jan 7 09:52:38 GMT 2008



On Mon, 7 Jan 2008, brett gardner wrote:

> The offending line is on line 793 of ResultSource.pm
>
> $ret{$k} = $for->get_column($v) if $for->has_column_loaded($v);

That's because has_column_loaded returns true if the data is in/was loaded 
from the database, you're calling new(), which doesnt insert a new row 
into the database. So it's doing the correct thing.

Call create() instead. That does new() and insert().

> my $undef_artist_cd = $schema->resultset("CD")->new_result({ 'title' => 
> 'badgers', 'year' => 2007 });
> 207 is($undef_artist_cd->has_column_loaded('artist'), '', 'FK not loaded');
> 208 is($undef_artist_cd->search_related('artist')->count, 3, 'open search 
> on undef FK');

new_result (or new) don't insert any data in the db, so this is perfectly 
correct.

> in 66relationship.t
>
> brett gardner wrote:
>> I have a schema where there are clients who have subscribers.
>> 
>> So there is an object "Client" which has a has_many relationship to 
>> "Subscriber".
>> 
>> If I do the following
>> 
>> my $client = $app->schema->resultset('Client')->find(...);
>> my $subscribers = $client->subscribers;
>> 
>> Then the relationship is correct and only pulls out the subscribers 
>> attached to that client.
>> 
>> But if I do the following.
>> 
>> my $client = $app->schema->resultset('Client')->new({});
>> my $subscribers = $client->subscribers;
>> Then all the subscribers are pulled out which is not ideal and 
>> potentially a very embarrassing privacy breach. Looking at the SQL 
>> generated by "$client->subscribers" it is not putting in the limiting 
>> where clause "WHERE me.client_id = ..."

As your row is not in the database, how would you expect it to do a where?


Did you really miss all this, or am I misunderstanding your problem?

Jess



More information about the DBIx-Class mailing list