<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Mar 10, 2017 at 8:38 PM, Darren Duncan <span dir="ltr"><<a href="mailto:darren@darrenduncan.net" target="_blank">darren@darrenduncan.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 2017-03-10 9:12 AM, Jorge Gonzalez wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
DBIC by default follows the convention that table names reflect the entity name<br>
in singular. If It detects table names in plural It uses a Lingua::* module to<br>
deduce the apropriate singular name, and names the clases with It.<br>
<br>
In your case, the table names IS "people", but the generated class name IS<br>
"Person", the singular for people.<br>
</blockquote>
<br>
Semantically this is one of those things I would argue that Entity Framework got (more) right and DBIC got (more) wrong.<br>
<br>
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.<br>
<br>
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".<br>
<br>
As this simple example in SQL (like typical generated SQL) demonstrates:<br>
<br>
select <a href="http://person.name" rel="noreferrer" target="_blank">person.name</a>, person.age from people person<br>
<br>
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.<br>
<br>
This is a loose Perl analogy:<br>
<br>
for my $person ($db->people) { print $person->name, $person->age }<br></blockquote><div><br></div><div>That's sort of what DBIC does already:</div><div><br></div><div>my $people = $db->resultset('Person')->search(...);</div><div>foreach my $person ($people->all) { ... }</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">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.<br></blockquote><div><br></div><div>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".</div><div><br></div><div>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.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
-- Darren Duncan<br>
<br>
<br>
______________________________<wbr>_________________<br>
List: <a href="http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class" rel="noreferrer" target="_blank">http://lists.scsys.co.uk/cgi-b<wbr>in/mailman/listinfo/dbix-class</a><br>
IRC: <a href="http://irc.perl.org#dbix-class" rel="noreferrer" target="_blank">irc.perl.org#dbix-class</a><br>
SVN: <a href="http://dev.catalyst.perl.org/repos/bast/DBIx-Class/" rel="noreferrer" target="_blank">http://dev.catalyst.perl.org/r<wbr>epos/bast/DBIx-Class/</a><br>
Searchable Archive: <a href="http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk" rel="noreferrer" target="_blank">http://www.grokbase.com/group/<wbr>dbix-class@lists.scsys.co.uk</a><br>
</blockquote></div><br></div></div>