[Dbix-class] convention for naming primary keys to avoid ambiguous selects

2008-11-25 Thread David Schmidt
Hello List, I used to have an id INTEGER PRIMARY KEY column in every table. Now I am using DBIC and repeatedly run into this kind of error. SELECT me.id, me.title, me.artist FROM cds me WHERE ( me.artist = ? ): '2' SELECT me.id, me.title, me.artist, artist.id, artist.name FROM cds me JOIN

Re: [Dbix-class] convention for naming primary keys to avoid ambiguousselects

2008-11-25 Thread Octavian Rasnita
From: David Schmidt [EMAIL PROTECTED] Hello List, I used to have an id INTEGER PRIMARY KEY column in every table. Now I am using DBIC and repeatedly run into this kind of error. SELECT me.id, me.title, me.artist FROM cds me WHERE ( me.artist = ? ): '2' SELECT me.id, me.title, me.artist,

Re: [Dbix-class] convention for naming primary keys to avoid ambiguousselects

2008-11-25 Thread David Schmidt
On Tue, Nov 25, 2008 at 5:31 PM, Octavian Rasnita [EMAIL PROTECTED] wrote: From: David Schmidt [EMAIL PROTECTED] Hello List, I used to have an id INTEGER PRIMARY KEY column in every table. Now I am using DBIC and repeatedly run into this kind of error. SELECT me.id, me.title, me.artist

Re: [Dbix-class] convention for naming primary keys to avoid ambiguousselects

2008-11-25 Thread Peter Rabbitson
David Schmidt wrote: On Tue, Nov 25, 2008 at 5:31 PM, Octavian Rasnita [EMAIL PROTECTED] wrote: From: David Schmidt [EMAIL PROTECTED] Hello List, I used to have an id INTEGER PRIMARY KEY column in every table. Now I am using DBIC and repeatedly run into this kind of error. SELECT me.id,

Re: [Dbix-class] convention for naming primary keys to avoid ambiguousselects

2008-11-25 Thread Noel Burton-Krahn
On Tue, Nov 25, 2008 at 9:45 AM, Peter Rabbitson [EMAIL PROTECTED] wrote: As far as the don't repeat yourself - what do you propose? Your query (the join-ed one) selects from two tables that have the same column. Unless you specify which column you are interested in, it is not safe for DBIC

Re: [Dbix-class] convention for naming primary keys to avoid ambiguousselects

2008-11-25 Thread Noel Burton-Krahn
On Tue, Nov 25, 2008 at 10:22 AM, Peter Rabbitson [EMAIL PROTECTED] wrote: Noel Burton-Krahn wrote: The problem is that DBIx has the smarts to prefix column names in the select clause, like select me.id, cds.id but not in the where clause where id=?. How does DBIC know if the user meant

Re: [Dbix-class] convention for naming primary keys to avoid ambiguousselects

2008-11-25 Thread Brian Phillips
prefixing the id column with the name of the relationship seems much more obvious than prefixing the base table's column with me. This doesn't seem like it would be too complicated to implement -- if the column given is not already prefixed by one or more table/relationship aliases, it could be

Re: [Dbix-class] convention for naming primary keys to avoidambiguousselects

2008-11-25 Thread Octavian Rasnita
From: Noel Burton-Krahn [EMAIL PROTECTED] This is a reasonable query: load a person with address by the person's id. The 'id' column is unambiguous in the search call. However, DBIx generates ambiguous SQL: DBIx::Class::ResultSet::count(): DBI Exception: DBD::mysql::st execute failed: Column

Re: [Dbix-class] convention for naming primary keys to avoidambiguousselects

2008-11-25 Thread Peter Rabbitson
Octavian Rasnita wrote: From: Noel Burton-Krahn [EMAIL PROTECTED] This is a reasonable query: load a person with address by the person's id. The 'id' column is unambiguous in the search call. However, DBIx generates ambiguous SQL: DBIx::Class::ResultSet::count(): DBI Exception:

Re: [Dbix-class] convention for naming primary keysto avoidambiguousselects

2008-11-25 Thread Octavian Rasnita
From: Peter Rabbitson [EMAIL PROTECTED] I think that if the query needs to search in a table named me which is not the primary table, it probably gives another name instead of me for the main table, so that name shouldn't need to be hard coded in the programs. By the way, does anyone know what

Re: [Dbix-class] convention for naming primary keys to avoidambiguousselects

2008-11-25 Thread Noel Burton-Krahn
On Tue, Nov 25, 2008 at 2:06 PM, Peter Rabbitson [EMAIL PROTECTED] wrote: Octavian Rasnita wrote: From: Noel Burton-Krahn [EMAIL PROTECTED] By the way, does anyone know what happends if a secondary table is named me? The name of the table is irrelevant as they are all aliased anyway. If