Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Structure::Field->add_unique_constraint( [qw/audited_table_id name/] ) required? #28

Open
bokutin opened this issue Aug 2, 2021 · 0 comments

Comments

@bokutin
Copy link

bokutin commented Aug 2, 2021

Hi,

One day, I started getting the following error.

DBIx::Class::Storage::DBI::select_single(): Query returned more than one row.  SQL that returns multiple rows is DEPRECATED for ->find and ->single

I tried s/carp/cluck/ on the line below.

https://github.com/Perl5/DBIx-Class/blob/03776361fc4081ae8413ff8d259f549c33569db5/lib/DBIx/Class/Storage/DBI.pm#L2765

DBIx::Class::Storage::DBI::select_single(DBIx::Class::Storage::DBI::Pg=HASH(0x805c11438), ARRAY(0x807373c90), ARRAY(0x8072d28b8), HASH(0x80704e9c0), HASH(0x8072c6090)) called at /usr/local/lib/perl5/site_perl/DBIx/Class/ResultSet.pm line 1101
DBIx::Class::ResultSet::single(DBIx::Class::ResultSet=HASH(0x8073736d8)) called at /usr/local/lib/perl5/site_perl/DBIx/Class/ResultSet.pm line 910
DBIx::Class::ResultSet::find(DBIx::Class::ResultSet=HASH(0x807373768), HASH(0x807395408)) called at /usr/local/lib/perl5/site_perl/DBIx/Class/Relationship/Base.pm line 731
DBIx::Class::Relationship::Base::find_related(DBIx::Class::Schema::AuditLog::Structure::AuditedTable=HASH(0x8072d2e10), "Field", HASH(0x807395408)) called at /usr/local/lib/perl5/site_perl/DBIx/Class/Relationship/Base.pm line 772
DBIx::Class::Relationship::Base::find_or_create_related(DBIx::Class::Schema::AuditLog::Structure::AuditedTable=HASH(0x8072d2e10), "Field", HASH(0x807395408)) called at /usr/local/lib/perl5/site_perl/DBIx/Class/AuditLog.pm line 131
DBIx::Class::AuditLog::_store_changes(MyApp::Schema::Result::Table1=HASH(0x8073959d8), DBIx::Class::Schema::AuditLog::Structure::Action=HASH(0x807398cd8), DBIx::Class::Schema::AuditLog::Structure::AuditedTable=HASH(0x8072d2e10), HASH(0x805a1e7c8), HASH(0x805a1e678)) called at /usr/local/lib/perl5/site_perl/DBIx/Class/AuditLog.pm line 74
DBIx::Class::AuditLog::update(MyApp::Schema::Result::Table1=HASH(0x8073959d8)) called at /usr/local/lib/perl5/site_perl/DBIx/Class/DynamicDefault.pm line 127
DBIx::Class::DynamicDefault::update(MyApp::Schema::Result::Table1=HASH(0x8073959d8)) called at /usr/local/lib/perl5/site_perl/DBIx/Class/TimeStamp/TimeMomentX_BOKUTIN.pm line 46
DBIx::Class::TimeStamp::TimeMomentX_BOKUTIN::update(MyApp::Schema::Result::Table1=HASH(0x8073959d8)) called at /usr/local/lib/perl5/site_perl/DBIx/Class/Row.pm line 1345
DBIx::Class::Row::update_or_insert(MyApp::Schema::Result::Table1=HASH(0x8073959d8)) called at /root/MyApp/script/../lib/MyApp/Cmd/Command/command1.pm line 113
MyApp::Cmd::Command::command1::__ANON__() called at /root/MyApp/script/../lib/MyApp/Schema.pm line 65
MyApp::Schema::__ANON__() called at /usr/local/lib/perl5/site_perl/Context/Preserve.pm line 23
Context::Preserve::preserve_context(CODE(0x807395fd8), "after", CODE(0x80508f930)) called at /root/MyApp/script/../lib/MyApp/Schema.pm line 68
MyApp::Schema::__ANON__(HASH(0x806fbc720)) called at /usr/local/lib/perl5/site_perl/DBIx/Class/Schema/AuditLog.pm line 66
DBIx::Class::Schema::AuditLog::__ANON__(HASH(0x806fbc720)) called at /usr/local/lib/perl5/site_perl/DBIx/Class/Storage/BlockRunner.pm line 130
DBIx::Class::Storage::BlockRunner::try {...} () called at /usr/local/lib/perl5/site_perl/Try/Tiny.pm line 102
eval {...} called at /usr/local/lib/perl5/site_perl/Try/Tiny.pm line 93
Try::Tiny::try(CODE(0x8070bc588), Try::Tiny::Catch=REF(0x8072d2d80)) called at /usr/local/lib/perl5/site_perl/DBIx/Class/Storage/BlockRunner.pm line 134
DBIx::Class::Storage::BlockRunner::__ANON__() called at /usr/local/lib/perl5/site_perl/Context/Preserve.pm line 23
Context::Preserve::preserve_context(CODE(0x80736ac90), "replace", CODE(0x807397060)) called at /usr/local/lib/perl5/site_perl/DBIx/Class/Storage/BlockRunner.pm line 213
DBIx::Class::Storage::BlockRunner::_run(undef, undef, HASH(0x806fbc720)) called at /usr/local/lib/perl5/site_perl/DBIx/Class/Storage/BlockRunner.pm line 105
DBIx::Class::Storage::BlockRunner::run(DBIx::Class::Storage::BlockRunner=HASH(0x80736aba0), CODE(0x806fccc60), HASH(0x806fbc720)) called at /usr/local/lib/perl5/site_perl/DBIx/Class/Storage.pm line 187
DBIx::Class::Storage::txn_do(DBIx::Class::Storage::DBI::Pg=HASH(0x805c11438), CODE(0x806fccc60), HASH(0x806fbc720)) called at /usr/local/lib/perl5/site_perl/DBIx/Class/Storage/DBI.pm line 861
DBIx::Class::Storage::DBI::txn_do(DBIx::Class::Storage::DBI::Pg=HASH(0x805c11438), CODE(0x806fccc60), HASH(0x806fbc720)) called at /usr/local/lib/perl5/site_perl/DBIx/Class/Schema.pm line 654
DBIx::Class::Schema::txn_do(MyApp::Schema=HASH(0x804e313a8), CODE(0x806fccc60), HASH(0x806fbc720)) called at /usr/local/lib/perl5/site_perl/DBIx/Class/Schema/AuditLog.pm line 75
DBIx::Class::Schema::AuditLog::txn_do(MyApp::Schema=HASH(0x804e313a8), CODE(0x80736a8d0), HASH(0x806fbc720)) called at /root/MyApp/script/../lib/MyApp/Schema.pm line 72
my application code $table1_row->update_or_insert ...

There seems to be a problem with the bottom line.

my $field = $table->find_or_create_related( 'Field',
{ name => $column } );

It seems to be as expected.

% psql db1
db1=# select array_agg(audited_table_id), array_agg(name) from audit_log_field group by audited_table_id, name having count(*) >= 2;
 array_agg  |            array_agg
------------+---------------------------------
 {13,13,13} | {col1,col1,col1}
(1 row)

db1=#

I think I need a bottom line.

diff --git a/lib/DBIx/Class/Schema/AuditLog/Structure/Field.pm b/lib/DBIx/Class/Schema/AuditLog/Structure/Field.pm
index 0aec51b..1777d84 100644
--- a/lib/DBIx/Class/Schema/AuditLog/Structure/Field.pm
+++ b/lib/DBIx/Class/Schema/AuditLog/Structure/Field.pm
@@ -26,6 +26,8 @@ __PACKAGE__->add_columns(

__PACKAGE__->set_primary_key('id');

+__PACKAGE__->add_unique_constraint( [qw/audited_table_id name/] );
+
__PACKAGE__->belongs_to(
    'AuditedTable',
    'DBIx::Class::Schema::AuditLog::Structure::AuditedTable',

DBIx-Class-AuditLog has not been updated, but it has been working fine for many years and I find it useful compared to the other DBIC-related Audit modules in CPAN.
I would like to continue to use it and would appreciate an update.

Thanks,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant