nullable column and might_have

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

nullable column and might_have

Mitchell Elutovich
I have something like the following on a custom result source

__PACKAGE__->add_columns(
  "xxxid",
  { data_type => "INT", default_value => undef, is_nullable => 1, size => 11 },
);

__PACKAGE__->might_have(
  "xxxd",
  "ForeignClass",
  { "foreign.id" => "self.xxxid" },
);

I'm getting the warning:

DBIx::Class::Relationship::HasOne::_validate_has_one_condition(): "might_have/has_one" must not be on columns with is_nullable set to true (MyClass/xxxid). This might indicate an incorrect use of those relationship helpers instead of belongs_to. at ... 

I don't understand why this for might_have might be incorrect, doesn't might_have imply it might be null?

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...
Reply | Threaded
Open this post in threaded view
|

Re: nullable column and might_have

Alexander Hartmaier
Hi Mitchell,
you've mistaken the direction of the relationship.
The result class with the xxxid column should have a belongs_to relationship to ForeignClass with { join_type => "LEFT" } so that rows where the xxxid column is NULL won't be missing from the resultset if you're joining the relationship.

In ForeignClass you could add a has_many relationship if you need it.

BR Alex

On 2014-06-05 13:54, Mitchell Elutovich wrote:
I have something like the following on a custom result source

__PACKAGE__->add_columns(
  "xxxid",
  { data_type => "INT", default_value => undef, is_nullable => 1, size => 11 },
);

__PACKAGE__->might_have(
  "xxxd",
  "ForeignClass",
  { "foreign.id" => "self.xxxid" },
);

I'm getting the warning:

DBIx::Class::Relationship::HasOne::_validate_has_one_condition(): "might_have/has_one" must not be on columns with is_nullable set to true (MyClass/xxxid). This might indicate an incorrect use of those relationship helpers instead of belongs_to. at ... 

I don't understand why this for might_have might be incorrect, doesn't might_have imply it might be null?


_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...



*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
T-Systems Austria GesmbH Rennweg 97-99, 1030 Wien
Handelsgericht Wien, FN 79340b
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
Notice: This e-mail contains information that is confidential and may be privileged.
If you are not the intended recipient, please notify the sender and then
delete this e-mail immediately.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...