Re: [Dbix-class] Differences in generated relationships
On Fri, 12 Feb 2021 at 08:47, Matthew Somerville wrote: > > On Thu, 11 Feb 2021 at 16:12, Dave Cross wrote: > > But I'd still like to know where those differences were coming from. > > In DBIx::Class::Schema::Loader::RelBuilder, in the > _relnames_and_method function, there is a "If more than one rel > between this pair of tables" section. Not sure I understand it fully, > but it looks like it does do something different the first time a > relation is added (when it looks like it pluralizes the column name), > as opposed to the second time when the temporary file is read in and > then might not do so. Interesting. Thanks, I'll have a look there. Cheers, Dave... ___ 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@lists.scsys.co.uk
Re: [Dbix-class] Differences in generated relationships
Thanks, yes, I've done that now. I've also changed the definition of the task_dependency table so that it's a proper linking table and therefore dbicdump generates many to many relationships for it - which means I'm far less likely to use the misnamed relationships. But I'd still like to know where those differences were coming from. Cheers, Dave... On Thu, 11 Feb 2021 at 15:52, Francisco Obispo wrote: > > You can influence what name the relationships and tables have with a map, > > see: https://metacpan.org/pod/DBIx::Class::Schema::Loader::Base#moniker_map > > Me preference is to use a dbic-conf.pl config file with all of the options. > > Best, > > On 11 Feb 2021, at 6:45, Dave Cross wrote: > > I have a database that contains tasks and the dependencies between > those tasks. It contains two tables: > CREATE TABLE `task` ( > `id` int(11) NOT NULL, > `done` tinyint(1) DEFAULT NULL, > `title` char(100) DEFAULT NULL, > PRIMARY KEY (`id`) > ) > CREATE TABLE `task_dependency` ( > `id` int(11) NOT NULL, > `previous_task_id` int(11) NOT NULL, > `next_task_id` int(11) NOT NULL, > PRIMARY KEY (`id`), > KEY `previous_task_id` (`previous_task_id`), > KEY `next_task_id` (`next_task_id`), > CONSTRAINT `task_dependency_ibfk_1` FOREIGN KEY (`previous_task_id`) > REFERENCES `task` (`id`), > CONSTRAINT `task_dependency_ibfk_2` FOREIGN KEY (`next_task_id`) > REFERENCES `task` (`id`) > ) > You'll see there are two foreign keys between task_dependency and > task. Other than the names, these columns are defined in exactly the > same way. > But when I use dbicdump to generate DBIC classes for these tables, > there's a subtle difference in the way the relationships are named. In > Task::Schema::Result::Task, I get the following relationships. > =head1 RELATIONS > =head2 task_dependencies_next_task > Type: has_many > Related object: L > =cut > __PACKAGE__->has_many( > "task_dependencies_next_task", > "Task::Schema::Result::TaskDependency", > { "foreign.next_task_id" => "self.id" }, > { cascade_copy => 0, cascade_delete => 0 }, > ); > =head2 task_dependency_previous_tasks > Type: has_many > Related object: L > =cut > __PACKAGE__->has_many( > "task_dependency_previous_tasks", > "Task::Schema::Result::TaskDependency", > { "foreign.previous_task_id" => "self.id" }, > { cascade_copy => 0, cascade_delete => 0 }, > ); > Note that the plurals are in different places in the relationship names. > task_dependencIES_next_task vs task_dependency_previous_taskS > If it matters, this is a MariaDB database. And here's the config file > I used with dbicdump: > schema_class Task::Schema > > dsn dbi:mysql:dbname=test;hostname=172.17.128.1 > user test > pass test > > > dump_directory ./Testlib > allow_extra_m2m_cols 1 > > I'm using DBIx::Class::Schema::Loader version 0.07049. > This isn't a major problem, but I just know that I'll keep typing > these names incorrectly :-/ > Is there anything I can do to fix this? Or is it expected behaviour? > Cheers, > Dave... > ___ > 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@lists.scsys.co.uk > > ___ > 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@lists.scsys.co.uk ___ 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@lists.scsys.co.uk
[Dbix-class] Differences in generated relationships
I have a database that contains tasks and the dependencies between those tasks. It contains two tables: CREATE TABLE `task` ( `id` int(11) NOT NULL, `done` tinyint(1) DEFAULT NULL, `title` char(100) DEFAULT NULL, PRIMARY KEY (`id`) ) CREATE TABLE `task_dependency` ( `id` int(11) NOT NULL, `previous_task_id` int(11) NOT NULL, `next_task_id` int(11) NOT NULL, PRIMARY KEY (`id`), KEY `previous_task_id` (`previous_task_id`), KEY `next_task_id` (`next_task_id`), CONSTRAINT `task_dependency_ibfk_1` FOREIGN KEY (`previous_task_id`) REFERENCES `task` (`id`), CONSTRAINT `task_dependency_ibfk_2` FOREIGN KEY (`next_task_id`) REFERENCES `task` (`id`) ) You'll see there are two foreign keys between task_dependency and task. Other than the names, these columns are defined in exactly the same way. But when I use dbicdump to generate DBIC classes for these tables, there's a subtle difference in the way the relationships are named. In Task::Schema::Result::Task, I get the following relationships. =head1 RELATIONS =head2 task_dependencies_next_task Type: has_many Related object: L =cut __PACKAGE__->has_many( "task_dependencies_next_task", "Task::Schema::Result::TaskDependency", { "foreign.next_task_id" => "self.id" }, { cascade_copy => 0, cascade_delete => 0 }, ); =head2 task_dependency_previous_tasks Type: has_many Related object: L =cut __PACKAGE__->has_many( "task_dependency_previous_tasks", "Task::Schema::Result::TaskDependency", { "foreign.previous_task_id" => "self.id" }, { cascade_copy => 0, cascade_delete => 0 }, ); Note that the plurals are in different places in the relationship names. task_dependencIES_next_task vs task_dependency_previous_taskS If it matters, this is a MariaDB database. And here's the config file I used with dbicdump: schema_class Task::Schema dsn dbi:mysql:dbname=test;hostname=172.17.128.1 user test pass test dump_directory./Testlib allow_extra_m2m_cols 1 I'm using DBIx::Class::Schema::Loader version 0.07049. This isn't a major problem, but I just know that I'll keep typing these names incorrectly :-/ Is there anything I can do to fix this? Or is it expected behaviour? Cheers, Dave... ___ 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@lists.scsys.co.uk
Re: [Dbix-class] Twitter accounts
May I make a suggestion? * I think it's good that DBIC has its own "official" Twitter account with the name @dbix_class * I think that account should be run by ribasushi * I think that Jess and the other people who have been contributing to the existing account over the years deserve some recognition for the work they've put it. So I suggest that Jess changes the name of the existing account to something like @dbic_news or @dbic_projects. That then frees up the @dbix_class name so that ribasushi can register it as a new account under his complete control. That way, ribasushi gets an official account under the best name and Jess hangs on to her account with its existing audience. It would be nice if the existing account could tweet a link to the new, official, account when it is set up, but I can see why Jess might not be disposed to do that. Oh, and I think that ribasushi owes a couple of apologies. Firstly, to Jess for taking her Twiter account without talking to her about it first, and secondly, to mst for accusing him of something that it now seems clear he had no involvement it. How does that sound? Dave... ___ 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@lists.scsys.co.uk
Re: [Dbix-class] ★ VOTE NOW: DBIC Governance and Namespace Control ★
n move forward. Therefore, I submit to the list the following two proposals: * PROPOSAL A: Primary permissions for DBIx::Class and related namespaces shall be managed under the amended DBIC community governance structure proposed by Matt Trout. Decisions about the future development of the project, including but not limited to stability policy, new development, branching and freezing shall be governed by the community under the same terms. The community will choose whether/how to continue active development of DBIC under that name or a separate name. Peter will choose whether/how to fork DBIC to a new namespace for independent development. * PROPOSAL B: Primary permissions for DBIx::Class and related namespaces shall be managed solely by Peter Ribasushi until he transfers it to another of his choosing or appears permanently incommunicado (whether by choice, accident or death).Decisions about the future development of the project, including but not limited to stability policy, new development, branching and freezing shall be made at Peter's sole discretion. Peter will choose whether/how to continue active development of DBIC under that or a separate name. The community, under the governance proposal, will choose whether/how to fork DBIC to a new namespace for independent development. List members should reply to this email with an email body indicating clearly "Proposal A" or "Proposal B". Other responses, such as "+1" or "me, too" replies to others' votes will be disregarded. Voting will close 72 hours after this email is sent. I will tally and announce results shortly thereafter. I will be sole arbiter of any voting irregularities. Once announced, I will transfer namespace permissions accordingly and consider the matter resolved. Regards, David [1] http://dbix-class.35028.n2.nabble.com/IMPORTANT-A-discussion-of-DBIC-governance-and-future-development-td7578987.html [2] http://dbix-class.35028.n2.nabble.com/PROPOSAL-Governance-and-sustainability-td7579228.html [3] http://dbix-class.35028.n2.nabble.com/IMPORTANT-A-discussion-of-DBIC-governance-and-future-development-tp7578987p7579158.html [4] http://dbix-class.35028.n2.nabble.com/GOVERNANCE-Aggregation-and-conclusion-tp7579168p7579175.html [5] http://dbix-class.35028.n2.nabble.com/Decision-time-which-fork-inherits-the-existing-DBIx-Class-namespace-tp7579255.html [6] http://dbix-class.35028.n2.nabble.com/GOVERNANCE-Aggregation-and-conclusion-tp7579168p7579184.html [7] http://dbix-class.35028.n2.nabble.com/GOVERNANCE-Aggregation-and-conclusion-tp7579168p7579208.html [8] http://dbix-class.35028.n2.nabble.com/GOVERNANCE-Aggregation-and-conclusion-tp7579168p7579225.html [9] http://dbix-class.35028.n2.nabble.com/An-answer-and-a-question-tp7579248p7579250.html [10] https://gist.github.com/xdg/836e6341b757df8b67cf26f02b6899d6 [11] https://gist.github.com/xdg/955519bee08658f9b60c6219a51fd0dd [12] http://dbix-class.35028.n2.nabble.com/GOVERNANCE-Aggregation-and-conclusion-td7579168.html -- David Golden <x...@xdg.me <mailto:x...@xdg.me>> Twitter/IRC/GitHub: @xdg ___ 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@lists.scsys.co.uk -- Dave Cross :: d...@dave.org.uk http://dave.org.uk/ @davorg ___ 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@lists.scsys.co.uk
Re: [Dbix-class] Decision time: which fork inherits the existing DBIx::Class namespace
On 03/12/16 23:16, Ashley Pond V wrote: the acrimony over a win-win situation is more telling than anything else that’s been said. What does that mean? Dave... ___ 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@lists.scsys.co.uk
Re: [Dbix-class] Decision time: which fork inherits the existing DBIx::Class namespace
On 03/12/2016 08:36, Chisel wrote: Sorry, I'm just sick of all this , and want to move forward. +1 I'm already on record as supporting mst's community-lead version of the project. I thought we'd pretty much reached a concensus on that a month ago and I really don't understand why this is still dragging on. Dave... ___ 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@lists.scsys.co.uk
Re: [Dbix-class] GOVERNANCE: Aggregation and conclusion
Quoting Matthias Zeichmann: On Tue, Nov 1, 2016 at 10:45 PM, Charlie Garrison wrote: On 1 Nov 2016, at 19:48, Thomas Klausner wrote: > I think a fork will not work. The "old" DBIC will stagnate, the "new" > will not gain traction. Everybody loses. Agreed. Another, same here -1 for forking, +1 for the original proposal Mee too. +1 Matt's proposal (new project team) -1 Andrew's proposal (forking) Dave... ___ 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@lists.scsys.co.uk
Re: [Dbix-class] GOVERNANCE: An actually concrete proposal w/bootstrap governance system
On 18/10/2016 19:03, Leo Lapworth wrote: On 18 October 2016 at 17:51, Matt S Troutwrote: =begin GOVERNANCE . =end GOVERNANCE What say ye? This gets the governance issue resolved and puts in place a framework that can evolve to fit what is needed at the time. +1 Anything more is just detail which can be added as required by the community or core updating the governance in accordance with these rules. What Leo said. +1 Dave... ___ 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@lists.scsys.co.uk
Re: [Dbix-class] Schema Components
Hi Darius, Thanks. Yes, I'd seen that documentation. It's a little sparse and seems to be aimed at writing components which are loaded into Result classes (InflateColumn::DateTime, TimeStamp and stuff like that). I suspect (but I could, of course, be wrong) that components which are loaded into Schema objects would follow different rules. Cheers, Dave... Quoting Darius Jokilehto <dariusjokile...@yahoo.co.uk>: Hello Dave, This might be what you're looking for: https://metacpan.org/pod/distribution/DBIx-Class/lib/DBIx/Class/Manual/Component.pod Darius On Friday, 16 September 2016, 17:09, Dave Cross <d...@dave.org.uk> wrote: In the documentation of DBIx::Class::Schema::Loader::Base there is a reference to adding "schema components"[1] to the generated classes. But I can't find any documentation on how you might write such a component - or any clearly-labelled examples of a schema component. I think I have an example of something that I'd like to write as a schema component. Please either tell me that I'm wrong, or gently nudge me in the right direction. Here's what I want to do. Recently I've found myself adding a useful "get_schema()" method to many of my schema classes. It looks something like this: sub get_schema { my @errs; foreach (qw[XXX_DB XXX_DB_USER XXX_DB_PASS XXX_DB_HOST]) { push @errs, $_ unless defined $ENV{$_}; } if (@errs) { croak "You need to set the following environment variables: @errs\n"; } return __PACKAGE__->connect( "dbi:mysql:database=$ENV{XXX_DB};host=$ENV{XXX_DB_HOST}", $ENV{XXX_DB_USER}, $ENV{XXX_DB_PASS}, { mysql_enable_utf8 => 1 } ); } The "XXX" is a placeholder for some prefix that is meaningful to whatever schema I'm working with and it will change with each project (as will, potentially, the DBD name and the options hash). I've been copying the code into my schema classes, but we all know what a Bad Idea that is. And a schema component seemed a likely-looking approach for getting round that. I thought I could write DBIx::Class::Component::GetSchema which adds the method to any schema class that loads it. But, as I said above, I can't find any explanations or examples of schema components that I can steal from. Does anyone have any suggestions? Cheers, Dave... [1] https://metacpan.org/pod/DBIx::Class::Schema::Loader::Base#schema_components ___ 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@lists.scsys.co.uk ___ 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@lists.scsys.co.uk
[Dbix-class] Schema Components
In the documentation of DBIx::Class::Schema::Loader::Base there is a reference to adding "schema components"[1] to the generated classes. But I can't find any documentation on how you might write such a component - or any clearly-labelled examples of a schema component. I think I have an example of something that I'd like to write as a schema component. Please either tell me that I'm wrong, or gently nudge me in the right direction. Here's what I want to do. Recently I've found myself adding a useful "get_schema()" method to many of my schema classes. It looks something like this: sub get_schema { my @errs; foreach (qw[XXX_DB XXX_DB_USER XXX_DB_PASS XXX_DB_HOST]) { push @errs, $_ unless defined $ENV{$_}; } if (@errs) { croak "You need to set the following environment variables: @errs\n"; } return __PACKAGE__->connect( "dbi:mysql:database=$ENV{XXX_DB};host=$ENV{XXX_DB_HOST}", $ENV{XXX_DB_USER}, $ENV{XXX_DB_PASS}, { mysql_enable_utf8 => 1 } ); } The "XXX" is a placeholder for some prefix that is meaningful to whatever schema I'm working with and it will change with each project (as will, potentially, the DBD name and the options hash). I've been copying the code into my schema classes, but we all know what a Bad Idea that is. And a schema component seemed a likely-looking approach for getting round that. I thought I could write DBIx::Class::Component::GetSchema which adds the method to any schema class that loads it. But, as I said above, I can't find any explanations or examples of schema components that I can steal from. Does anyone have any suggestions? Cheers, Dave... [1] https://metacpan.org/pod/DBIx::Class::Schema::Loader::Base#schema_components ___ 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@lists.scsys.co.uk
Re: [Dbix-class] Getting primary key (id) after populate
On 10/09/15 19:04, Hetényi Csaba wrote: Dear friends Sorry for newbie question! I'd like to know, how to get the last inserted row's primary key after a populate? I have the following code in a Catalyst app (it inserts data to related tables too, but in the main table: FoldkHrsz only one row): # DB Populate my $hrsz_res = $c->model('DB::FoldkHrsz')->populate([ { %$hrsz_data, foldk_alreszlets => \@$alreszlet_AoH, foldk_szeljegyzetts => \@$szeljegyzett_adat_AoH, foldk_szolgalmis => \@$szolgalmi_adat_AoH, foldk_tulajs => \@$tulaj_adat_AoH, foldk_jogok_tenyeks => \@$jogok_tenyek_adat_AoH }, ]); After this, if i try to get the last inserted row's PK with this: $hrsz_res->id; ..gives an error: "Can't call method "id" on unblessed reference at ..." I know, that the populate method's result is: \@result_objects (scalar context) | @result_objects (list context) but don't know, how to use them? You're calling populate() in scalar context, so you're getting an array reference back. You want the first element in the referenced array. $hrsz->[0]->id; But a better solution might be to call populate() in list context. my ($hrsz_res) = $c->model('DB::FoldkHrsz')->populate([ ... ]); Then $hrsz_res will contain a row object which you can use in the way you were originally expecting. $hrsz->id; hth, Dave... ___ 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@lists.scsys.co.uk
[Dbix-class] Perl School: Database Programming with Perl and DBIx::Class
Hi, I'm running my Perl School class on DBIC again this coming Saturday (June 8th). It's at Google Campus in London. It's a full-day course and tickets cost £30. Full details at http://prls.ch/dbic2list Do you know anyone who could benefit from a one-day introduction to DBIC? Please feel free to pass on this email to them. Cheers, Dave... -- Dave Cross :: d...@dave.org.uk http://dave.org.uk/ @davorg ___ 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@lists.scsys.co.uk
[Dbix-class] Fwd: Perl School 4: Database Programming with Perl and DBIx::Class
I thought that people on this list might be interested in this too. Or, more likely, that you might know people who think *should* be interested :-) - Forwarded message from d...@dave.org.uk - Date: Wed, 06 Feb 2013 07:18:52 + From: Dave Cross d...@dave.org.uk Subject: Perl School 4: Database Programming with Perl and DBIx::Class Perl School 4 is this Saturday (9th Feb). It's an introduction to DBIx::Class. It's a full-day course for £30 and it takes place at Google Campus in London. There are still a number of tickets available. Would you benefit from an introduction to DBIC? Or is there someone you work with who would benefit from an introduction to DBIC? Sign up at http://perlschool.co.uk/upcoming/ Cheers, Dave... -- Dave Cross :: d...@dave.org.uk http://dave.org.uk/ @davorg - End forwarded message - ___ 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@lists.scsys.co.uk
[Dbix-class] Time-based Relatiosnhips
I think I'm missing something obvious here. But I've fried my brain thinking about it. A foo can have many associated bars. So I have this. __PACKAGE__-has_many( 'bars' = 'MyDB::Result::Bar', { 'foreign.foo_id' = 'self.id' }, ); But, each bar has start and end dates associated with it. So at most one bar record is active for a foo at any given time[1]. I thought I could do something like this: __PACKAGE__-might_have( 'active_bar' = 'MyDB::Result::Bar', { 'foreign.foo_id' = 'self.id', 'foreign.start' = { '=' = \'now()' }, 'foreign.end = { '=' = \'now()' } }, ); But I get an error saying 'Invalid rel cond val'. This comes from code in DBIx::Class::ResultSource::_resolve_condition which checks that all values in the condition hash include the string 'self'. So how do I model this relationship? Am I mad for even trying? Dave... [1] Yes, this is hard to maintain. But the schema isn't going to change. ___ 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@lists.scsys.co.uk
Re: [Dbix-class] Time-based Relatiosnhips
Quoting Peter Rabbitson rabbit+d...@rabbit.us: On Wed, Nov 09, 2011 at 01:11:12PM +, Dave Cross wrote: So how do I model this relationship? https://metacpan.org/module/DBIx::Class::Relationship::Base#condition and then grep for To specify joins which describe more than a simple equality... The documentation is currently below suboptimal, we'd be delighted to get a patch addressing the issue (better =head's or somesuch) Ah. That looks good. Thanks for pointing it out. Dave... ___ 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@lists.scsys.co.uk
[Dbix-class] DBIC Article in LXF
Linux Format (LXF) is a general purpose Linux magazine in the UK. It seems to be aimed at a largely non-technical audience. A few months ago, they published a really terrible Perl tutorial. I wrote and complained about it[1]. They offered me the chance to do better. LXF151 hits the shelves about now and it contains my article. It's a really simple introduction to DBIC. I'm not sure what the my re-publication rights are, but I've put the PDF online at http://dave.org.uk/LXF151.code_perl.pdf. If they complain, I may have to remove it. Hope you enjoy it. Dave... [1] http://perlhacks.com/2011/04/an-open-letter-to-linux-format/ ___ 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@lists.scsys.co.uk
[Dbix-class] DBIC, MySQL and UTF8
I'm sure I had this working before but it's all gone very strange now. I have a MySQL db where all the tables contain UTF8 data. Actually, as far as I can see, the only problematic character is the £ sign. From my understanding of MySQL, I think this select proves that the data is UTF8: mysql select ord(substring(description, 48, 1)) from invoice_line where invoice = 347; ++ | ord(substring(description, 48, 1)) | ++ | 49827 | | 49827 | | 49827 | | 49827 | | 49827 | ++ 5 rows in set (0.03 sec) 49827 is (194 * 256) + 163 - hence 0xC2 0xA3[1]. My DBIC connect looks like this: my $sch = MyData::DB-connect( 'dbi:mysql:database=mydata;', 'user', '', { mysql_enable_utf8 = 1 } ); But when I look at the data in the description attribute within the Perl, the £ sign is just 0xA3 - which is the Latin1 encoding. The 0xC2 has been dropped. DB2 x map { ord $_ } (split //, $_-description)[45 .. 50] 0 64 1 32 2 163 3 52 4 48 5 48 (Those characters in the string are '@ £400') If I run: $_-description(encode('utf8', decode('latin1', $_-description))); Then I get: DB4 x map { ord $_ } (split //, $_-description)[45 .. 51] 0 64 1 32 2 194 3 163 4 52 5 48 6 48 Which is what I was expecting in the first place. I thought that { mysql_enable_utf8 = 1 } was supposed to be the solution to all these problems. But I'm obviously missing something. This is one of those occasions where I'm hoping that I'm being really stupid and there's an obvious problem staring me in the face. Can you see it? :-/ Cheers, Dave... [1] See http://www.fileformat.info/info/unicode/char/a3/index.htm ___ 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@lists.scsys.co.uk
Re: [Dbix-class] DBIC Schema to DDL
On 02/10/2010 11:08 AM, iain wrote: Dave Cross wrote: Is there a way to take a set of DBIx::Class schema classes and (re-)generate the DDL that was originally used to generate the classes? I use http://search.cpan.org/~ribasushi/DBIx-Class-0.08118/lib/DBIx/Class/Schema/Versioned.pm for this See, I'd looked at that and decided that it worked on DDL files. But now, I've gone back and actually _read_ the documentation - and everything works fine. Thanks for your help. I now have a database[1]. Cheers, Dave... [1] And, perhaps more usefully, no further need to put my DDL in source code control :) ___ 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@lists.scsys.co.uk
[Dbix-class] Help with Many to Many Relationships
I've having a brain freeze trying to implement a query in DBIC. I'm sure I'm missing something obvious. Here's the situation. Assume standard DBIC classes (created by Schema::Loader). Four tables - Director, Film, Actor, ActorInFilm A Director directs many Films. A Film has many Actors An Actor is in Films So the ActorInFilm table models the many-to-many relationship between Actors and Films. My problem is: given an actor and a director, get the list of films that they worked on together. So the result will be a resultset containing Film objects (or, alternatively, a list of Film objects). I've been thinking about it too long and I can no longer think straight. Even explaining the problem in this email hasn't helped. Please tell me what I'm missing. Cheers, Dave... ___ 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@lists.scsys.co.uk
Re: [Dbix-class] Help with Many to Many Relationships
On 17/06/2009 13:12, Ian Wells wrote: 2009/6/17 Jason Galeali...@eightdegrees.com.au: Hi Dave, package DB::Film; ... # has many actors __PACKAGE__-has_many('film_actor_maps' = 'DB::FilmActorMap', 'product'); __PACKAGE__-many_to_many('actors' = 'film_actor_maps', 'actor'); __PACKAGE__-belongs_to('director' = 'DB::Director'); I'd do it the other way around: package DB::Actor; ... # Has many films __PACKAGE__-has_many('actor_film_maps' = 'DB::FilmActorMap', 'product'); __PACKAGE__-many_to_many('films' = 'actor_film_maps', 'film'); my $rs = $actor-films-search(director = 39); Thanks. That's exactly what I was looking for. I'd have got there myself too - given another eight or ten hours of trying :-/ Cheers, Dave... ___ 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@lists.scsys.co.uk
[Dbix-class] Replicated DB - Best Practices
I'm looking for some advice on best practice for dealing with replicated MySQL databases. My current client has a large database which is split across a RW master and several RO slaves (I believe that's how MySQL replication always works). They're just toying with replacing a lot of their DB code with DBIx::Class. I assume that other people have been working with similar architecture and I'd be grateful for any advice you might have. In particular we're thinking about problems like: * How to decide whether to connect to the master or the slave * Do we maintain a pool of database handles to both masters and slaves. * Whether it ever makes sense to upgrade a slave connection to a master connection on the fly * How referential integrity works in a world where a slave can be out of date compared to the master (actually, we know the answer to that one - it doesn't) All suggestions, gratefully received. Cheers, Dave... ___ 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@lists.scsys.co.uk
Re: [Dbix-class] London Perl Mongers Article What's Wrong with ORM
Jonathan Yu wrote: Hi all: Just wondering what all of your thoughts are with respect to this article: http://dave.org.uk/talks/lpm/2006/orm/ Note that it's from 2006. I retired that talk after I gave it at the Birmingham YAPC and had most of the audience telling me that I was out of date as DBIx::Class could already do pretty much everything on my list. I think the thing about constraints is important. Is it possible to implement custom constraints on data? What I mean is, parse the constraint from the SQL database, and then use that to validate data prior to INSERTs and UPDATEs? Then you could validate data before it even enters the database. But, if DBIx::Class can't already do that then I'd _love_ to see it :) Cheers, Dave... ___ 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@lists.scsys.co.uk
Re: [Dbix-class] Overriding Standard Methods
John Goulah wrote: On Wed, Dec 3, 2008 at 10:19 AM, Dave Cross [EMAIL PROTECTED] wrote: I think I'm missing something obvious here. Feel free to point out my stupidity. I have a set of DBIC classes that have been generated by Schema::Loader. I want to overload the delete method so that instead of actually deleting the row the deleted flag gets set to true[1]. I can add a method to the class like this: sub rm { my $self = shift; $self-deleted(1); $self-update; } and call rm instead of delete. Then everything works. But I don't want to call the method rm, I want to call it delete. If I call it delete, then my method doesn't get called. It goes into DBIx::Class::Relationship::CascadeActions::delete and that passes control to DBIx::Class::Row::delete - completely missing my method. What am I missing? Cheers, Dave... [1] Yes, this should be a trigger. But triggers are banned from this database. This should work: sub delete { my $self = shift; # do stuff return $self-next::method(@_); } Thanks for the advice, but it doesn't seem to fix anything. And, looking at it, I don't see how it could. If my delete method isn't being called, then how can adding code to it fix the problem? Actually, my problem is slightly more complex. I want to put the delete method in a base class that all of my classes inherit from. Some of these classes have a deleted flag and others don't. So my code should really look like this: sub delete { my $self = shift; if ($self-can(deleted)) { $self-deleted(1); $self-update; } else { $self-SUPER::delete; } } And because of the C3 stuff, that SUPER:: also probably needs to be replaced with some next::method magic. But getting the method to be called is the first problem :) Dave... ___ 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@lists.scsys.co.uk
Re: [Dbix-class] Overriding Standard Methods
Dave Cross wrote: So I can either write a component or hack around with the Class::C3 inheritance list. Decisions, decisions :) Turns out that my existing base class works just fine as a component. Thanks for your help. Dave... ___ 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@lists.scsys.co.uk