15:06:00 #startmeeting Development IRC meeting, 23 September 2014: DBIC 15:06:00 Meeting started Tue Sep 23 15:06:00 2014 UTC. The chair is tcohen. Information about MeetBot at http://wiki.debian.org/MeetBot. 15:06:00 Useful Commands: #action #agreed #help #info #idea #link #topic #startvote. 15:06:00 The meeting name has been set to 'development_irc_meeting__23_september_2014__dbic' 15:06:10 good morning 15:06:12 #topic Introductions 15:06:13 #info wahanui, a bot that has become sentient 15:06:14 good morning gmcharlt 15:06:25 please introduce yourselves using #info name 15:06:32 #info Martin Renvoize, PTFS Europe 15:06:34 #info Katrin Fischer, BSZ, Germany 15:06:39 #info Tomas Cohen Arazi, Universidad Nacional de Cordoba 15:06:56 #info Colin Campbell PTFS Europe Ltd 15:07:05 do we need to ping ribasushi at some point ;) 15:07:12 #info Galen Charlton, Equinox 15:07:12 hi 15:07:36 #info Bernardo Gonzalez Kriegel 15:07:54 #info Jonathan Druart, BibLibre 15:08:47 ok 15:08:54 #info Jared Camins-Esakov, C & P Bibliography Services 15:09:29 khall? 15:10:07 ok 15:10:26 This is an unusual meeting 15:10:31 to talk about a specific subject 15:10:56 #topic RM introduction 15:11:27 #info Owen Leonard, Athens County Public Libraries 15:11:34 The main subject is our adoption of DBIC, and how we do it 15:11:46 #link http://wiki.koha-community.org/wiki/DBIC_discussion_overview 15:12:27 the main discussion is related to how much stuff we expect DBIC to provide, and how to do it 15:12:46 there are mainly two discussed POV 15:13:25 on the one hand (a) benefit from DBIC magic, and put (some degree) of business logic into it 15:14:22 and on the other (b) relying on the ORM only for abstracting the DB and using it to implement our own API in which business logic should be put 15:14:41 this issue is related to point (1) on th elink 15:15:15 I've already expressed that my personal POV is that we should keep the current way of using DBIC 15:15:44 i.e. using it inside modules, that can be unit tested 15:16:03 +1 for UT 15:16:27 hmm 15:16:41 I think that point perhaps could be clarified - may I go through a somewhat lengthly example? 15:17:12 please 15:17:24 go for it 15:17:42 OK, so when we are talking about business logic, there are at least two ways in can manifest itself 15:17:53 point 1 : i think since there are aleardy modules nammed nearly like a db table (ie C4/Borrowers.pm), I'll vote for a) 15:18:06 umm, may I please have the floor 15:18:19 yep sorry 15:18:22 :) 15:18:48 so, one way business logic can manifest is as attributes of the underlying entities that we're dealing with 15:18:56 so take, for example, item records 15:19:27 one way of modeling an item record is to follow the DB schema closely 15:19:42 on the assumption that we've done a reasonably good job with our relational model 15:19:50 which, in many places, we have 15:19:53 in others, we haven't 15:19:59 but let's stick with items for now 15:20:38 one thing we could say is that, OK, a Koha::Schema::Result::Item is a decent base class for an item record 15:21:02 but that it doesn't /exactly/ give everything we need to ask of any item record 15:21:33 and the big example is ->effective_itemtype 15:22:02 there's a bit of business logic there, as of course the effective item type for circ polices depends on the item-level_itypes system preference 15:22:40 but it's somethat that can be well-encapsulated as (effectively) an attribute of K::S::R::Item 15:22:57 and there's a lot going for that approach 15:23:30 1. it is definitely testable -- there's nothing stopping unit tests from being written on K::S::R::* objects 15:24:04 2. it gives a *single* place to ask the question - "what is the effective item type of an item?" 15:24:17 so in that respect, I quite like it 15:24:28 next, I'm going to move on to an example where things are less clear-cut 15:24:33 namely, bibs 15:25:05 so, as everybody here knows, you need to look at both biblio and biblioitems to get all of the info regarding a bib entity 15:25:36 (and of course, that represents drift from Koha's original quasi-FRBR model, but that's in the past, water under the bridge, etc.) 15:26:04 but the upshot - this is an example where the current relational data model is flawed for our current purposes 15:26:41 as if you start from a K::S::R::Biblio object ... you have to go through some convulations to get at everything you might want to ask of a bib record object 15:27:06 now you /could/ do things like add K::S::R::Biblio->marc to grab the MARC record 15:27:15 and so on... but that's stretching things 15:27:42 and it's vulnerabile to cases where we would want to redo the data structure 15:27:53 (which, we probably want to do in the long run) 15:28:42 so there, I think the situation calls for (say) a Koha::Biblio object that can be *composed* of (say) a K::S::R::Biblio and a K::S::R::bibioitems object 15:29:17 but if we right such a class ... it would be useful to delegate as much to the underlying K::S::R attribute methods as possible 15:29:43 partcularly when we want to start traveling to related objects like items 15:30:02 so, now I'm going to move on to my third (and final) example 15:30:31 and that's business logic that pretty much doesn't naturally look like an attribute of an object 15:30:58 for example: the question of calculating the due date of a new loan 15:31:13 now you can envision procedural code 15:31:26 e.g., my $due_date = Koha::Loans::get_due_date($patron, $item) 15:31:33 or a more OO approach 15:31:46 my $loan = Koha::Loans->new($patron, $item) 15:32:00 where, in effect, the constructor of that object does things like calculate the due date 15:32:19 (and throw exceptions if the loan is against policy) 15:33:01 but however you do it, the upshot is that it wouldn't be a good idea to add lots of methods to Koha::S::R::Issue to try to do all of this 15:33:04 but rather, build a new class 15:33:09 (or build procedural code) 15:33:29 so what I've done so far is provided three examples of the sort of business logic we have to deal with 15:33:39 thx gmcharlt - that#s really helpful 15:33:49 next, I'm going to talk about testing 15:34:40 first, I submit that it doesn't matter for the prupose of being able to test things whether code exists as a K::S::R method or as a K::Object method to be reachable for testing 15:34:43 either way, it can be tested 15:35:05 IOW, I'm sayng that how we decide the DBIC usage questions need not be inlfuenced all that much by testing concerns 15:35:20 as we have both db-dependent and non-db-dependent ways of testing 15:35:26 * tcohen agrees 15:35:51 so as far as my current thinking on the overall matter is concerned 15:36:48 1. I dislike adding layers of classes needlessly -- in particular, if a K::S::R object represents an entity adequately, I see no reason not to use it as a base class or a very thinly-encapsulated entity 15:37:11 e.g., K::S::R::Item->effective_itemtype is a good example 15:38:12 2. Not *everything* can be done that way -- e.g., I would call for a Koha::Biblio class to be written that (among other things) contains K::S::R::Biblio and K::S::R::Biblioitems objects, and makes some effort to hide the details of those tables 15:38:26 as we KNOW that those tables are eventually going to significantly change 15:39:05 so the upshot: on question #1, I fall firmly in the middle 15:39:29 now we may want to provide some syntactic sugar to the reduce the typing to instantiant a K::S::R object 15:40:34 but for areas where our data model is good -- I think a lot can be done by adding attribute methods to the underlying K::S::R classes 15:41:16 and (to answer in part a question that cait had asked me) borrowers is an example where the database schema mostly matches how we view the objects 15:41:45 so I think that for now K::S::R::Borrowers would be a good base class 15:42:21 now that's not to say that we couldn't have a Koha::Borrowers, but for now it shoudl delegate/pass along as much as psosible to K::S::R::Borrowers 15:42:38 hm so we would put something there that pulls information from ohter tables as well? 15:42:47 sorry i am still trying to wrap my mind around it :) 15:42:59 well, K::S::R via DBIC does that for us for free 15:43:02 welcome ribasushi 15:43:15 so it would get the extended patron attributes etc. 15:43:16 at least in the cases where the underlying tables have FK relationsips 15:43:33 ok thx :) 15:43:50 as far as our quesinon #6 is concerned -- I'm not a fan of a Koha::Object and/or Koha::Object::Set as a universal base class 15:43:53 too much weight 15:44:06 if anything should be a universal base class, I'd go for Class::Accessor 15:44:14 and thus ends my monologue for now 15:44:45 but to summarize: I'm suggesting a hybrid approach, one of whose big advantages is that it will allow us to continue to switch thigns over to using DBIC incrementally 15:45:21 * gmcharlt goes under his desk to look for his hands, which have fallen off 15:45:49 other opinions please? 15:45:50 * cait helps searching... hard to put a hand back on with no hands... 15:47:09 gmcharlt: how do implement set/list? 15:47:12 I think gmcharlt described it pretty succinctly really. 15:47:13 you* 15:48:19 Joubu: one moment before I answer you, want to check something 15:50:05 rangi: around? if I remember correctly you was not fond of extending K::S::R into "Koha::Object" 15:50:38 Joubu: so for now, my view is to use DBIC::ResultSet where possible 15:51:06 gmcharlt: even on front end stuff like the .pl scripts¿ 15:51:23 Joubu: 3 am in nz i think :( 15:51:28 Yes it makes for clear robust code 15:51:30 provide constructures where needed so that you can (say) take a Koha::S::R::Biblio and initiatialize a Koha::Biblio object from it 15:51:49 and uses plain old arrays and hashes for sets ;) 15:52:06 * jcamins agrees with gmcharlt on everything that gmcharlt said. 15:52:35 and as far as the scripts are concerned... yeah, I personally have no problem fetching data directly using DBIC in them 15:52:36 ok, my fieling is the same, except I would create a Koha::Biblios or Koha::Biblio::Set 15:53:06 but the key thing is this: the scripts should be focused on GETTING the objects, but they wouldn't be doing much if any business logic 15:53:34 and where possible, would be passing the K::S::R and K::* objects directly to the template so that the TT code can take care of fetching attributes for display 15:53:59 gmcharlt: do you have a poc to show us? A class with search+crud? 15:54:33 Joubu: I disagree in the general case -- i.e., I wouldn't want to see a Koha::Vendor::Set or the like 15:54:44 however, catalog searches are a special case 15:55:00 patron searches? 15:55:13 i.e., I could certainly see a Koha::CatalogSearchResultSet class 15:55:19 "passing the K::S::R and K::* objects directly to the template" => to me, we should not manipulate both. Only Koha::* 15:55:29 manipulate in pl 15:55:43 No need for a Set object you just have a set of object much as ResultSet itself is a set of objs 15:56:32 Joubu: I think our main difference of opinion is that I think K::S::R objects should be used when they suffice, and that Koha::* classes should be created when they are necessary, but that we can do both and be happy 15:57:02 gmcharlt: I just want consistency, I would like to create all objects using the same way 15:57:05 from the POV of the templates, either way it's going to look like [% object.attribute %] anyway 15:57:24 my $patron = Koha::Patron->new($patron_info)->insert 15:58:05 Joubu: I want consistent *interfaces* for accessors -- I care much less about the base class 15:58:07 From the callers vire both should look the same 15:58:19 and @patrons = Koha::PatronSet->search(name => 'smith') 15:58:26 s/PatronSet/WhatYouWant 15:59:39 Joubu: I don't want to (or want anybody) to have to write 100+ sets of boilerplate objects to do that when K::S::R can handle that for most objects 15:59:40 HOWEVER 16:00:05 I don't like the hybrid approach: when does it suffice to use K::S::R? 16:00:06 there might be the possibility of some AUTOLOAD magic 16:00:21 tcohen: items, for now 16:00:26 but to continue my thought 16:01:23 there might be the possibility of some AUTOLOAD magic or the like so that we can chop out the "Schema::Result" part of the names to use the DBIC classes directly 16:01:38 and where needed, e.g., Koha::Biblio, override when something that's hand-constructed 16:02:05 (11518 (effective_itemtype) still NSO, for 6months, and we didn't get enough thoughts) 16:03:24 i think we becasue we needed ot have this discussion - hopefully the bugs stuck now can then start moving forward 16:04:03 I really would like to see how you (everybody) would like to write code in pl file. It's clear to me, but I didn't get ideas/thoughts from others. Don't you have a POC/try somewhere to show? 16:04:47 I think it's the first question to consider 16:05:40 When we answered, we should try to have a consistent, simple, easy to use and flexible API 16:07:33 hum, ping? 16:07:34 Using deft allegory, the authors have provided an insightful and intuitive explanation of one of Unix's most venerable networking utilities. http://www.amazon.com/Story-about-Reading-Railroad-Books/dp/0448421658 16:08:04 i'm here 16:08:05 been using dbic and its nice to have a consitent reliable approach where we need classes that span tables like biblio the api should be as similar as possible 16:08:10 i think the dual approach makes sense tome, but it might be hard to judge at times which route is better 16:09:06 i think in the long run we will have a better model, which makes DBIC classes represent our objects better 16:09:10 BUT 16:09:21 we will still need to put business logic on top of that 16:09:56 and in that case, extending Koha::Schema::ResultSet::* should be the way to go 16:10:24 we could think Koha::Biblio makes sense "only" because of a bad underlying model 16:11:23 if we can rely on DBIC for everything 16:12:12 right - my inclination is to have the RDBMS model match the desired class structure where possible 16:12:32 but knowing that it it won't be always possible 16:13:19 as far as Joubu's question is concerned - well, current DBIC use in scripts like admin/categorie.pl isn't actually horrid, but I would grant that it's certainly verbose 16:13:35 the trick would be improving that without burying the DBIC classes udner too many layers 16:14:08 by *too many* you mean one, right? 16:14:50 yep, if we can avoid it :) 16:15:35 it's for the lisiblity, maintenability 16:15:52 s/lisibility/readability 16:16:58 Does nobody want to write some code? 16:17:05 just some lines here? 16:18:26 any more comments/opinions? 16:20:21 Joubu: I'm not sure you get to make demands on anybody's time but your own -- but I think I have some ideas on how to implemnt some concision 16:20:27 ok, i think we have exhausted the discussion for now. I'll try to sumarize on the wiki Joubu set for this topic 16:20:36 in the meantime, I've got more utf8 test cases to write today 16:20:50 :-D 16:21:18 gmcharlt: do u have some sample test we can take a look at? 16:21:19 gmcharlt: I just would like to know how continue to develop 16:21:38 utf8 test cases first, then we'll see 16:21:49 gmcharlt: I had some tries, but they seem to be bad. 16:22:06 Joubu: you're talking about using DBIC? 16:22:35 gmcharlt: I don't ask a lot. Just how instanciate an object, save it. And possibly a search 16:23:04 Joubu: I know; I'll get to it, but I'm not making promises as to when 16:23:10 I need to unfreeze this situation 16:23:15 s/I/We 16:23:22 I don't disagree 16:23:34 I think the discussion today has been helpful 16:23:48 and should get even more help when the NZers weigh in 16:24:01 IOW, I think we're making progress, as slow as it may seem 16:24:15 Joubu++ # keeping at it 16:25:34 ok, i think the meeting concluded 16:25:49 There are tries on 12830, 12896, 8007, 10363 16:25:56 some more thoughts will be expressed later 16:26:09 so all approches is bad, and I will try something else 16:26:11 and we will work on this in person, during the hackfest 16:26:40 I encourage people that disagrees with a specific dev approach, to make it explicit 16:26:41 or 1 is good, and it would be good to know :) 16:26:46 how it should be done 16:26:54 i think the hackfest will be a chance and we can post the code for others to look at 16:26:59 http://www.gliffy.com/go/publish/6160409 16:27:02 because otherwise it discourages participation 16:27:16 Joubu: on a completely different topic, I just now learned of a code2bib French mailing list... is it like code4lib? 16:27:19 for information, maybe not a lot of people is aware of that. 16:27:56 gmcharlt: what the name of the ml? 16:27:58 is* 16:28:05 Joubu: code2bib 16:28:20 ok, thanks every1 16:28:25 #endmeeting