On Fri, Mar 10, 2017 at 8:38 PM, Darren Duncan <dar...@darrenduncan.net> wrote:
> On 2017-03-10 9:12 AM, Jorge Gonzalez wrote: > >> DBIC by default follows the convention that table names reflect the >> entity name >> in singular. If It detects table names in plural It uses a Lingua::* >> module to >> deduce the apropriate singular name, and names the clases with It. >> >> In your case, the table names IS "people", but the generated class name IS >> "Person", the singular for people. >> > > Semantically this is one of those things I would argue that Entity > Framework got (more) right and DBIC got (more) wrong. > > Semantically a table is a collection of rows where typically each row > represents a singular entity, for example a single person, and a table > represents a simple set/bag/array of those entities, and is collectively > for example a group of 0..N people. > > I believe table-typed variables such as those in SQL databases should be > named using the same naming conventions that are appropriate for arrays, > after what the whole collection represents, such as "people", whereas > row-typed variables would best be named for what a single row is, such as > "person". > > As this simple example in SQL (like typical generated SQL) demonstrates: > > select person.name, person.age from people person > > Here "people" is the name of the table-typed SQL variable, and "person" is > the name of the SQL range variable declared in the "select" that represents > each individual row in turn. > > This is a loose Perl analogy: > > for my $person ($db->people) { print $person->name, $person->age } > That's sort of what DBIC does already: my $people = $db->resultset('Person')->search(...); foreach my $person ($people->all) { ... } And so, DBIC would ideally name any classes/objects/variables representing > a single person as Person while any representing a collection would be > People, which is the behavior that "code first" Entity Framework defaults > to. > The DBIC result source is named Person and each result (row) object is a Person. You should (in my opinion) read $db->resultset('Person') as "collection of objects of type Person". DBIC is nice in that way; it doesn't force you to remember when something is plural or singular - it's always singular. If you want to name your resultset $people, you are perfectly free to do so. > > -- Darren Duncan > > > _______________________________________________ > 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