Skip to content

Commit cec12db

Browse files
committed
Added generate_options_by_name_where option to Wing::Role::Result::Parent.
1 parent bfe655c commit cec12db

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ This file tracks the changes to Wing over time. Especially
44
with respect to new features and compatibility changes.
55
==========================================================
66

7+
2022-12-16
8+
* Added generate_options_by_name_where option to Wing::Role::Result::Parent.
9+
710
2022-05-04
811
* Fix permission errors that happen when trying to Ouch an object in the message field.
912

lib/Wing/Role/Result/Parent.pm

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ sub wing_parent_field {
5555
my $out = $orig->($self, %describe_options);
5656
my @parent_ids;
5757
my %parent_options;
58-
my $parents = $self->result_source->schema->resultset($options->{related_class})->search(undef,{order_by => 'name'});
58+
my $where = undef;
59+
if ($options->{generate_options_by_name_where}) {
60+
$where = $options->{generate_options_by_name_where};
61+
}
62+
my $parents = $self->result_source->schema->resultset($options->{related_class})->search($where,{order_by => 'name'});
5963
while (my $parent = $parents->next) {
6064
push @parent_ids, $parent->id;
6165
$parent_options{$parent->id} = $parent->name;
@@ -181,6 +185,10 @@ Scalar. Optional. The field to be created in this class to store the relationshi
181185
182186
Boolean. Optional. Defaults to C<0>. If set to C<1> this will add an enumerated options list to the object description when C<include_options> is specified. The options will be C<id> / C<name> pairs.
183187
188+
=item generate_options_by_name_where
189+
190+
Hash containing a DBIx::Class where clause. Only used if C<generate_options_by_name> is enabled. Used to filter the list to a subset.
191+
184192
=item skip_ref_check
185193
186194
Boolean. Optional. Normally adding a parent adds a check to make sure that the id that refers to a parent actually exists. When C<skip_ref_checK> is true that validation is skipped. This is really only useful if you want to create the parent at the same time you insert this object into the database.

0 commit comments

Comments
 (0)