Skip to content

Instantly share code, notes, and snippets.

@mrenvoize
Created January 5, 2018 08:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrenvoize/debbcfacc5c4e3dc75e813410b3f868b to your computer and use it in GitHub Desktop.
Save mrenvoize/debbcfacc5c4e3dc75e813410b3f868b to your computer and use it in GitHub Desktop.
Multi-create Fun
my $list_changeResult = $c->db->resultset('ListChange')->create(
{
list_id => $list_id,
request => [{requester_id => $requester_id, assignee_id => $assignee_id, status => 'new'}],
message => {
buffer_id => $list_id,
user_id => $requester_id,
text => "Priority tag '$tag' was removed from the system.",
important => 1
}
}
);
use utf8;
package Rebus::Schema::Result::ListChange;
=head1 NAME
Rebus::Schema::Result::ListChange
=cut
use strict;
use warnings;
use base 'DBIx::Class::Core';
=head1 COMPONENTS LOADED
=over 4
=item * L<Helper::Row::NumifyGet>
=back
=cut
__PACKAGE__->load_components(qw( Helper::Row::NumifyGet ));
=head1 TABLE: C<list_changes>
=cut
__PACKAGE__->table("list_changes");
=head1 ACCESSORS
=head2 id
data_type: 'integer'
is_auto_increment: 1
is_nullable: 0
is_numeric: 1
=head2 list_id
data_type: 'integer'
is_foreign_key: 1
is_nullable: 1
is_numeric: 1
=head2 message_id
data_type: 'integer'
is_foreign_key: 1
is_nullable: 1
is_numeric: 1
=cut
__PACKAGE__->add_columns(
"id", {data_type => "integer", is_auto_increment => 1, is_nullable => 0, is_numeric => 1},
"list_id", {data_type => "integer", is_foreign_key => 1, is_nullable => 0, is_numeric => 1},
"message_id", {data_type => "integer", is_foreign_key => 1, is_nullable => 1, is_numeric => 1},
);
=head1 PRIMARY KEY
=over 4
=item * L </id>
=back
=cut
__PACKAGE__->set_primary_key("id");
=head1 RELATIONS
=head2 request
Type: has_one
Related object: L<Rebus::Schema::Result::Request>
=cut
__PACKAGE__->has_one(
"request",
"Rebus::Schema::Result::Request",
{"foreign.list_change_id" => "self.id"},
{is_foreign_key_constraint => 1, is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE"},
);
=head2 list
Type: belongs_to
Related object: L<Rebus::Schema::Result::List>
=cut
__PACKAGE__->belongs_to(
"list", 'Rebus::Schema::Result::List',
{"foreign.id" => "self.list_id"},
{on_delete => "CASCADE", on_update => "CASCADE", "is_foreign_key_constraint" => 1},
);
=head2 buffer
Type: might_have
Related object: L<Rebus::Schema::Result::Buffer>
=cut
__PACKAGE__->might_have(
"buffer",
'Rebus::Schema::Result::Buffer',
{"foreign.list_id" => "self.list_id"},
{join_type => "left", is_foreign_key_constraint => 0, cascade_delete => 0},
);
=head2 message
Type: belongs_to
Related object: L<Rebus::Schema::Result::Buffermessage>
=cut
__PACKAGE__->belongs_to(
"message",
'Rebus::Schema::Result::Buffermessage',
{'foreign.id' => 'self.message_id'},
{'join_type' => 'left', 'on_delete' => 'SET NULL'},
);
1;
use utf8; [258/9963]
package Rebus::Schema::Result::Request;
=head1 NAME
Rebus::Schema::Result::Request
=cut
use strict;
use warnings;
use base 'DBIx::Class::Core';
=head1 COMPONENTS LOADED
=over 4
=item * L<DBIx::Class::InflateColumn::DateTime>
=item * L<Helper::Row::NumifyGet>
=back
=cut
__PACKAGE__->load_components(qw(InflateColumn::DateTime Helper::Row::NumifyGet));
=head1 TABLE: C<request>
=cut
__PACKAGE__->table("requests");
=head1 ACCESSORS
=head2 id
data_type: 'integer'
is_auto_increment: 1
is_nullable: 0
is_numeric: 1
=head2 requester_id
data_type: 'integer'
is_foreign_key: 1
is_nullable: 0
is_numeric: 1
=head2 assignee_id
data_type: 'integer'
is_foreign_key: 1
is_nullable: 1
is_numeric: 1
=head2 status
data_type: 'text'
is_foreign_key: 1
is_nullable: 0
=head2 updated
data_type: 'timestamp'
datetime_undef_if_invalid: 1
default_value: current_timestamp
is_nullable: 0
retrieve_on_insert: 1
=head2 created
data_type: 'timestamp'
datetime_undef_if_invalid: 1
default_value: current_timestamp
is_nullable: 0
retrieve_on_insert: 1
[179/9963]
=head2 material_change_id
data_type: 'integer'
is_foreign_key: 1
is_nullable: 1
is_numeric: 1
=head2 material_copy_id
data_type: 'integer'
is_foreign_key: 1
is_nullable: 1
is_numeric: 1
=head2 list_change_id
data_type: 'integer'
is_foreign_key: 1
is_nullable: 1
is_numeric: 1
=head2 buffer_submission_id
data_type: 'integer'
is_foreign_key: 1
is_nullable: 1
is_numeric: 1
=cut
__PACKAGE__->add_columns(
"id",
{data_type => "integer", is_auto_increment => 1, is_nullable => 0, is_numeric => 1},
"requester_id",
{data_type => "integer", is_foreign_key => 1, is_nullable => 0, is_numeric => 1},
"assignee_id",
{data_type => "integer", is_foreign_key => 1, is_nullable => 1, is_numeric => 1},
"status",
{data_type => "text", is_nullable => 0,},
"updated",
{
data_type => "timestamp",
datetime_undef_if_invalid => 1,
default_value => \"current_timestamp",
is_nullable => 0,
retrieve_on_insert => 1
},
"created",
{
data_type => "timestamp",
datetime_undef_if_invalid => 1,
default_value => \"current_timestamp",
is_nullable => 0,
retrieve_on_insert => 1
},
'material_change_id',
{data_type => "integer", is_foreign_key => 1, is_nullable => 1, is_numeric => 1, default_value => \"null"},
'material_copy_id',
{data_type => "integer", is_foreign_key => 1, is_nullable => 1, is_numeric => 1, default_value => \"null"},
'list_change_id',
{data_type => "integer", is_foreign_key => 1, is_nullable => 1, is_numeric => 1, default_value => \"null"},
'buffer_submission_id',
{data_type => "integer", is_foreign_key => 1, is_nullable => 1, is_numeric => 1, default_value => \"null"},
);
=head1 PRIMARY KEY
=over 4
=item * L</id>
=back
=cut
__PACKAGE__->set_primary_key("id");
=head1 CONSTRAINTS
=head2 material_change
Type: Unique
=cut
__PACKAGE__->add_unique_constraint(material_change => [qw/material_change_id/]);
=head2 material_copy
Type: Unique
=cut
__PACKAGE__->add_unique_constraint(material_copy => [qw/material_copy_id/]);
=head2 list_change
Type: Unique
=cut
__PACKAGE__->add_unique_constraint(list_change => [qw/list_change_id/]);
=head2 buffer_submission
Type: Unique
=cut
__PACKAGE__->add_unique_constraint(buffer_submission => [qw/buffer_submission_id/]);
=head2 Multiple Table Inheritance - XOR
=over 4
=item * material_change
=item * material_copy
=item * list_change
=item * buffer_submission
=back
=cut
sub sqlt_deploy_hook {
my ($self, $sqlt_table) = @_;
return $sqlt_table->add_constraint(
type => 'CHECK',
name => 'requests_xor',
expression =>
"(material_copy_id IS NOT NULL)::integer + (buffer_submission_id IS NOT NULL)::integer + (list_change_id IS NOT NULL)::integer + (material_change_id IS NOT NULL)::integer = 1"
);
}
=head1 SPECIAL ACCESSORS
=head2 type
Name: type
=cut
sub type {
my $self = shift;
return 'change' if defined($self->material_change_id);
return 'copy' if defined($self->material_copy_id);
return 'buffer_submission' if defined($self->buffer_submission_id);
return 'list_change' if defined($self->list_change_id);
return;
}
=head1 RELATIONS
=head2 assignee
Type: belongs_to
Related object: L<Rebus::Schema::Result::User>
=cut
__PACKAGE__->belongs_to(
"assignee" => "Rebus::Schema::Result::User",
{id => "assignee_id"}, {is_deferrable => 1, on_delete => "RESTRICT", on_update => "RESTRICT", join_type => "left"},
);
=head2 requester
Type: belongs_to
Related object: L<Rebus::Schema::Result::User>
=cut
__PACKAGE__->belongs_to(
"requester" => "Rebus::Schema::Result::User",
{id => "requester_id"}, {is_deferrable => 1, on_delete => "RESTRICT", on_update => "RESTRICT"},
);
=head2 request_actions
Type: has_many
Related object: L<Rebus::Schema::Result::RequestAction>
=cut
__PACKAGE__->has_many(
"request_actions" => "Rebus::Schema::Result::RequestAction",
{"foreign.request_id" => "self.id"}, {cascade_copy => 0, cascade_delete => 1},
);
=head2 material_copy
Type: belongs_to
Related object: L<Rebus::Schema::Result::MaterialCopy>
=cut
__PACKAGE__->belongs_to(
'material_copy',
'Rebus::Schema::Result::MaterialCopy',
{'foreign.id' => 'self.material_copy_id'},
{join_type => 'left', is_deferrable => 1, on_delete => "RESTRICT", on_update => "RESTRICT"},
);
=head2 material_change
Type: belongs_to
Related object: L<Rebus::Schema::Result::MaterialChange>
=cut
__PACKAGE__->belongs_to(
'material_change',
'Rebus::Schema::Result::MaterialChange',
{'foreign.id' => 'self.material_change_id'},
{join_type => 'left', is_deferrable => 1, on_delete => "RESTRICT", on_update => "RESTRICT"},
);
=head2 buffer_submission
Type: belongs_to
Related object: L<Rebus::Schema::Result::BufferSubmission>
=cut
__PACKAGE__->belongs_to(
'buffer_submission',
'Rebus::Schema::Result::BufferSubmission',
{'foreign.id' => 'self.buffer_submission_id'},
{join_type => 'left', is_deferrable => 1, on_delete => "RESTRICT", on_update => "RESTRICT"},
);
=head2 list_change
Type: belongs_to
Related object: L<Rebus::Schema::Result::ListChange>
=cut
__PACKAGE__->belongs_to(
'list_change',
'Rebus::Schema::Result::ListChange',
{'foreign.id' => 'self.list_change_id'},
{join_type => 'left', is_deferrable => 1, on_delete => "RESTRICT", on_update => "RESTRICT"},
);
1;
@mrenvoize
Copy link
Author

It's the code in Controller-Priority.pm that fails to run and I believe it's the request relation that's the problem.

I initially tried using a hashref instead of an arrayref which resulted in the 'request' row being created first which causes a check constraint to fail (check constraints can't be deferred in postgres as far as I'm aware :( ). Following this through I noted that the docs actually state one should use an arrayref for a has_one/has_many relationship for multi-create and hence I switched it, but this leads to the error below:

Priority removal transaction failed with Result object instantiation requires a hashref as argument at /home/rebus/rebus-list/script/../local/lib/perl5/DBIx/Class/Schema.pm line 1118. [26/9215]
DBIx::Class::Schema::throw_exception(Rebus::Schema=HASH(0x7ff95de68ea0), "Result object instantiation requires a hashref as argument") called at /home/rebus/rebus-list/script/../local/lib/perl5/DBIx/Class/ResultSource.pm line 2379
DBIx::Class::ResultSource::throw_exception(DBIx::Class::ResultSource::Table=HASH(0x7ff95d39db88), "Result object instantiation requires a hashref as argument") called at /home/rebus/rebus-list/script/../local/lib/perl5/DBIx/Class/ResultSet.pm line 4010
DBIx::Class::ResultSet::throw_exception(Rebus::Schema::ResultSet=HASH(0x7ff9604a26e8), "Result object instantiation requires a hashref as argument") called at /home/rebus/rebus-list/script/../local/lib/perl5/DBIx/Class/ResultSet.pm line 2588
DBIx::Class::ResultSet::new_result(Rebus::Schema::ResultSet=HASH(0x7ff9604a26e8), ARRAY(0x7ff95b47b150)) called at /home/rebus/rebus-list/script/../local/lib/perl5/DBIx/Class/Row.pm line 135
DBIx::Class::Row::__new_related_find_or_new_helper(Rebus::Schema::Result::ListChange=HASH(0x7ff9604d0008), "request", ARRAY(0x7ff95b47b150)) called at /home/rebus/rebus-list/script/../local/lib/perl5/DBIx/Class/Row.pm line 212
DBIx::Class::Row::new("Rebus::Schema::Result::ListChange", HASH(0x7ff95b46c9c8)) called at /home/rebus/rebus-list/script/../local/lib/perl5/DBIx/Class/ResultSet.pm line 2593
DBIx::Class::ResultSet::new_result(Rebus::Schema::ResultSet=HASH(0x7ff9607f3780), HASH(0x7ff9604cfe28)) called at /home/rebus/rebus-list/script/../local/lib/perl5/DBIx/Class/ResultSet.pm line 2891
DBIx::Class::ResultSet::create(Rebus::Schema::ResultSet=HASH(0x7ff9607f3780), HASH(0x7ff9604cfe28)) called at /home/rebus/rebus-list/script/../lib/Rebus/Controller/Priority.pm line 383
Rebus::Controller::Priority::ANON() called at /home/rebus/rebus-list/script/../local/lib/perl5/DBIx/Class/Storage/BlockRunner.pm line 130
DBIx::Class::Storage::BlockRunner::try {...} () called at /home/rebus/rebus-list/script/../local/lib/perl5/Try/Tiny.pm line 103
eval {...} called at /home/rebus/rebus-list/script/../local/lib/perl5/Try/Tiny.pm line 94
Try::Tiny::try(CODE(0x7ff95ca601a0), Try::Tiny::Catch=REF(0x7ff9607a40a0)) called at /home/rebus/rebus-list/script/../local/lib/perl5/DBIx/Class/Storage/BlockRunner.pm line 134
DBIx::Class::Storage::BlockRunner::ANON() called at /home/rebus/rebus-list/script/../local/lib/perl5/Context/Preserve.pm line 23
Context::Preserve::preserve_context(CODE(0x7ff9604dab18), "replace", CODE(0x7ff95b3e27e8)) called at /home/rebus/rebus-list/script/../local/lib/perl5/DBIx/Class/Storage/BlockRunner.pm line 213
DBIx::Class::Storage::BlockRunner::_run(DBIx::Class::Storage::BlockRunner=HASH(0x7ff96049e920), CODE(0x7ff96078b4a0)) called at /home/rebus/rebus-list/script/../local/lib/perl5/DBIx/Class/Storage/BlockRunner.pm line 105
DBIx::Class::Storage::BlockRunner::run(DBIx::Class::Storage::BlockRunner=HASH(0x7ff96049e920), CODE(0x7ff96078b4a0)) called at /home/rebus/rebus-list/script/../local/lib/perl5/DBIx/Class/Storage.pm line 187
DBIx::Class::Storage::txn_do(DBIx::Class::Storage::DBI::Pg=HASH(0x7ff95de690b0), CODE(0x7ff96078b4a0)) called at /home/rebus/rebus-list/script/../local/lib/perl5/DBIx/Class/Storage/DBI.pm line 862
DBIx::Class::Storage::DBI::txn_do(DBIx::Class::Storage::DBI::Pg=HASH(0x7ff95de690b0), CODE(0x7ff96078b4a0)) called at /home/rebus/rebus-list/script/../local/lib/perl5/DBIx/Class/Schema.pm line 654
DBIx::Class::Schema::txn_do(Rebus::Schema=HASH(0x7ff95de68ea0), CODE(0x7ff96078b4a0)) called at /home/rebus/rebus-list/script/../lib/Rebus/Controller/Priority.pm line 405
Rebus::Controller::Priority::try {...} () called at /home/rebus/rebus-list/script/../local/lib/perl5/Try/Tiny.pm line 101
eval {...} called at /home/rebus/rebus-list/script/../local/lib/perl5/Try/Tiny.pm line 94
Try::Tiny::try(CODE(0x7ff960521a18), Try::Tiny::Catch=REF(0x7ff95b1750e0)) called at /home/rebus/rebus-list/script/../lib/Rebus/Controller/Priority.pm line 415
Rebus::Controller::Priority::remove(Rebus::Controller::Priority=HASH(0x7ff9607f5e00)) called at /home/rebus/rebus-list/script/../local/lib/perl5/Mojolicious.pm line 138
Mojolicious::ANON(undef, Rebus::Controller::Priority=HASH(0x7ff9607f5e00), CODE(0x7ff9607f8978), 1) called at /home/rebus/rebus-list/script/../local/lib/perl5/Mojolicious/Plugins.pm line 15
Mojolicious::Plugins::ANON() called at /home/rebus/rebus-list/script/../lib/Rebus/Plugin/Authorization.pm line 227
Rebus::Plugin::Authorization::_api_auth(CODE(0x7ff9604b05c0), Rebus::Controller::Priority=HASH(0x7ff9607f5e00), CODE(0x7ff9607f8978), 1) called at /home/rebus/rebus-list/script/../lib/Rebus/Plugin/Authorization.pm line 31
Rebus::Plugin::Authorization::ANON(CODE(0x7ff9604b05c0), Rebus::Controller::Priority=HASH(0x7ff9607f5e00), CODE(0x7ff9607f8978), 1) called at /home/rebus/rebus-list/script/../local/lib/perl5/Mojolicious/Plugins.pm line 15
Mojolicious::Plugins::ANON() called at /home/rebus/rebus-list/script/../local/lib/perl5/Mojolicious/Plugins.pm line 18
Mojolicious::Plugins::emit_chain(Mojolicious::Plugins=HASH(0x7ff959d17970), "around_action", Rebus::Controller::Priority=HASH(0x7ff9607f5e00), CODE(0x7ff9607f8978), 1) called at /home/rebus/rebus-list/script/../local/lib/perl5/Mojolicious/Routes.pm line 87
Mojolicious::Routes::_action(Rebus=HASH(0x7ff95ada6b00), Rebus::Controller::Priority=HASH(0x7ff9607f5e00), CODE(0x7ff9607f8978), 1) called at /home/rebus/rebus-list/script/../local/lib/perl5/Mojolicious/Routes.pm line 166
Mojolicious::Routes::_controller(Mojolicious::Routes=HASH(0x7ff959d173e8), Mojolicious::Controller=HASH(0x7ff9605421e0), HASH(0x7ff960493848), 1) called at /home/rebus/rebus-list/script/../local/lib/perl5/Mojolicious/Routes.pm line 36
Mojolicious::Routes::continue(Mojolicious::Routes=HASH(0x7ff959d173e8), Mojolicious::Controller=HASH(0x7ff9605421e0)) called at /home/rebus/rebus-list/script/../local/lib/perl5/Mojolicious/Routes.pm line 44
Mojolicious::Routes::dispatch(Mojolicious::Routes=HASH(0x7ff959d173e8), Mojolicious::Controller=HASH(0x7ff9605421e0)) called at /home/rebus/rebus-list/script/../local/lib/perl5/Mojolicious.pm line 129
Mojolicious::dispatch(Rebus=HASH(0x7ff95ada6b00), Mojolicious::Controller=HASH(0x7ff9605421e0)) called at /home/rebus/rebus-list/script/../local/lib/perl5/Mojolicious.pm line 139
Mojolicious::ANON(undef, Mojolicious::Controller=HASH(0x7ff9605421e0)) called at /home/rebus/rebus-list/script/../local/lib/perl5/Mojolicious/Plugins.pm line 15
Mojolicious::Plugins::ANON() called at /home/rebus/rebus-list/script/../local/lib/perl5/Mojolicious.pm line 201
eval {...} called at /home/rebus/rebus-list/script/../local/lib/perl5/Mojolicious.pm line 201
Mojolicious::_exception(CODE(0x7ff9607a64a0), Mojolicious::Controller=HASH(0x7ff9605421e0)) called at /home/rebus/rebus-list/script/../local/lib/perl5/Mojolicious/Plugins.pm line 15
Mojolicious::Plugins::ANON() called at /home/rebus/rebus-list/script/../local/lib/perl5/Mojolicious/Plugins.pm line 18
Mojolicious::Plugins::emit_chain(Mojolicious::Plugins=HASH(0x7ff959d17970), "around_dispatch", Mojolicious::Controller=HASH(0x7ff9605421e0)) called at /home/rebus/rebus-list/script/../local/lib/perl5/Mojolicious.pm line 145
Mojolicious::handler(Rebus=HASH(0x7ff95ada6b00), Mojo::Transaction::HTTP=HASH(0x7ff9608123d0)) called at /home/rebus/rebus-list/local/lib/perl5/Mojo/Server.pm line 68
Mojo::Server::ANON(Mojo::Server::Prefork=HASH(0x7ff9593f6f40), Mojo::Transaction::HTTP=HASH(0x7ff9608123d0)) called at /home/rebus/rebus-list/local/lib/perl5/Mojo/EventEmitter.pm line 15
Mojo::EventEmitter::emit(Mojo::Server::Prefork=HASH(0x7ff9593f6f40), "request", Mojo::Transaction::HTTP=HASH(0x7ff9608123d0)) called at /home/rebus/rebus-list/local/lib/perl5/Mojo/Server/Daemon.pm line 103
Mojo::Server::Daemon::ANON(Mojo::Transaction::HTTP=HASH(0x7ff9608123d0)) called at /home/rebus/rebus-list/local/lib/perl5/Mojo/EventEmitter.pm line 15
Mojo::EventEmitter::emit(Mojo::Transaction::HTTP=HASH(0x7ff9608123d0), "request") called at /home/rebus/rebus-list/script/../local/lib/perl5/Mojo/Transaction/HTTP.pm line 60
Mojo::Transaction::HTTP::server_read(Mojo::Transaction::HTTP=HASH(0x7ff9608123d0), "DELETE /api/priorities/5 HTTP/1.1\x{d}\x{a}Host: rl-dev-1.rebus.ptfsa"...) called at /home/rebus/rebus-list/local/lib/perl5/Mojo/Server/Daemon.pm line 219
Mojo::Server::Daemon::_read(Mojo::Server::Prefork=HASH(0x7ff9593f6f40), "ca4d8bea3473adbb3728ecf9c2b07cf3", "DELETE /api/priorities/5 HTTP/1.1\x{d}\x{a}Host: rl-dev-1.rebus.ptfsa"...) called at /home/rebus/rebus-list/local/lib/perl5/Mojo/Server/Daemon.pm line 200
Mojo::Server::Daemon::ANON(Mojo::IOLoop::Stream=HASH(0x7ff960521040)) called at /home/rebus/rebus-list/local/lib/perl5/Mojo/EventEmitter.pm line 15
Mojo::EventEmitter::emit(Mojo::IOLoop::Stream=HASH(0x7ff960521040), "read", "DELETE /api/priorities/5 HTTP/1.1\x{d}\x{a}Host: rl-dev-1.rebus.ptfsa"...) called at /home/rebus/rebus-list/local/lib/perl5/Mojo/IOLoop/Stream.pm line 99
Mojo::IOLoop::Stream::_read(Mojo::IOLoop::Stream=HASH(0x7ff960521040)) called at /home/rebus/rebus-list/local/lib/perl5/Mojo/IOLoop/Stream.pm line 48
Mojo::IOLoop::Stream::ANON(Mojo::Reactor::EV=HASH(0x7ff95a5d91e8)) called at /home/rebus/rebus-list/local/lib/perl5/Mojo/Reactor/Poll.pm line 143
eval {...} called at /home/rebus/rebus-list/local/lib/perl5/Mojo/Reactor/Poll.pm line 143
Mojo::Reactor::Poll::_try(Mojo::Reactor::EV=HASH(0x7ff95a5d91e8), "I/O watcher", CODE(0x7ff9608364b8), 0) called at /home/rebus/rebus-list/local/lib/perl5/Mojo/Reactor/EV.pm line 46
Mojo::Reactor::EV::ANON(EV::IO=SCALAR(0x7ff96077efa0), 3) called at /home/rebus/rebus-list/local/lib/perl5/Mojo/Reactor/EV.pm line 25
eval {...} called at /home/rebus/rebus-list/local/lib/perl5/Mojo/Reactor/EV.pm line 25
Mojo::Reactor::EV::start(Mojo::Reactor::EV=HASH(0x7ff95a5d91e8)) called at /home/rebus/rebus-list/local/lib/perl5/Mojo/IOLoop.pm line 136
Mojo::IOLoop::start(Mojo::IOLoop=HASH(0x7ff95a0e9700)) called at /home/rebus/rebus-list/local/lib/perl5/Mojo/Server/Prefork.pm line 163
Mojo::Server::Prefork::_spawn(Mojo::Server::Prefork=HASH(0x7ff9593f6f40)) called at /home/rebus/rebus-list/local/lib/perl5/Mojo/Server/Prefork.pm line 100
Mojo::Server::Prefork::_manage(Mojo::Server::Prefork=HASH(0x7ff9593f6f40)) called at /home/rebus/rebus-list/local/lib/perl5/Mojo/Server/Prefork.pm line 85
Mojo::Server::Prefork::run(Mojo::Server::Prefork=HASH(0x7ff9593f6f40)) called at /home/rebus/rebus-list/local/lib/perl5/Mojo/Server/Hypnotoad.pm line 74
Mojo::Server::Hypnotoad::run(Mojo::Server::Hypnotoad=HASH(0x7ff9593e2388), "/home/rebus/rebus-list/script/rebus") called at /home/rebus/rebus-list/local/bin/hypnotoad line 14

@cxw42
Copy link

cxw42 commented Dec 16, 2019

@mrenvoize I am getting the same error ("requires a hashref as argument") --- were you able to figure it out? Thanks!

Edit I posted too soon :) . request is a has_one relationship, so the arrayref should not be used.

In my case, I had a singular relationship as well (belongs_to), so it's a hashref, not an arrayref. Per this, it's only an arrayref for has_many relationships.

For any future readers, my example was:

In the Result class:

__PACKAGE__->belongs_to(
    'admin_role',
    'Foo::Schema::Result::Role',
    { 'foreign.id' => 'self.admin_role_id' },
);

When creating:

$rs->create({
    name => 'Foo',
    admin_role => { role_name => 'Foo role' },
});

The key for the related-row creation was admin_role (the relationship/accessor name), NOT admin_role_id (the actual foreign-key name).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment