|
Hi.
Normally, what you need in your class is this variable: protected $_primary = 'your_primary_key'; OR protected $_primary = array( 'primary_1', 'primary_2' .....); This error might occur when the model cannot detect the primary key, often it's because you have more than one. --Best regards and good luck Hilmar 2010/5/25 zamanphp <[hidden email]>
|
|
But what if table have no primary key?
Regards, Saša Stamenković On Wed, Jun 2, 2010 at 12:53 PM, Hilmar Hallbjörnsson <[hidden email]> wrote: Hi. |
|
Hi,
If you set protected $_primary = 'your_primary_key'; it is not being checked if it is really the private key. So if it fits your needs you can set any filed of the table to be used as primary key. regards Petar On 06/02/2010 02:19 PM, Саша Стаменковић wrote: > But what if table have no primary key? > > Regards, > Saša Stamenković > > > On Wed, Jun 2, 2010 at 12:53 PM, Hilmar Hallbjörnsson <[hidden email] > <mailto:[hidden email]>> wrote: > > Hi. > > Normally, what you need in your class is this variable: > > protected $_primary = 'your_primary_key'; OR > > protected $_primary = array( 'primary_1', 'primary_2' .....); > > This error might occur when the model cannot detect the primary key, > often it's because you have more than one. > > --Best regards and good luck > Hilmar > > 2010/5/25 zamanphp <[hidden email] <mailto:[hidden email]>> > > > hi all > I'm using Zend_Cachefor Zend_Db_Table_Abstract > Sometimes Htay following occurs: > "A table must have a primary key, but none was found" > While I'm have in the my table primary key. > and Refresh the page to be resolved > What Is Problem؟ > > -- > View this message in context: > http://zend-framework-community.634137.n4.nabble.com/Zend-Db-Table-Exception-A-table-must-have-a-primary-key-but-none-was-found-tp2230044p2230044.html > Sent from the Zend DB mailing list archive at Nabble.com. > > > |
|
Then I don't see the reason for Zend_Db_Table to throw exception. Might that be a bug?
Regards, Saša Stamenković On Wed, Jun 2, 2010 at 1:49 PM, Petar Dzhambazov <[hidden email]> wrote: Hi, |
|
Ah, probably to keep find() method satisfied.
Regards, Saša Stamenković On Wed, Jun 2, 2010 at 1:51 PM, Саша Стаменковић <[hidden email]> wrote: Then I don't see the reason for Zend_Db_Table to throw exception. Might that be a bug? |
|
It is probably the 80/20 % rule. Most of the time your tables will have
primary keys and when they don't they are some sort of special case. Then you either work with adapter methods or extend Zend_Db_Table to fit your case. regards Petar On 06/02/2010 02:52 PM, Саша Стаменковић wrote: > Ah, probably to keep find() method satisfied. > > Regards, > Saša Stamenković > > > On Wed, Jun 2, 2010 at 1:51 PM, Саша Стаменковић <[hidden email] > <mailto:[hidden email]>> wrote: > > Then I don't see the reason for Zend_Db_Table to throw exception. > Might that be a bug? > > Regards, > Saša Stamenković > > > > On Wed, Jun 2, 2010 at 1:49 PM, Petar Dzhambazov <[hidden email] > <mailto:[hidden email]>> wrote: > > Hi, > If you set > > protected $_primary = 'your_primary_key'; > > it is not being checked if it is really the private key. So if > it fits your needs you can set any filed of the table to be used > as primary key. > > regards > Petar > > > On 06/02/2010 02:19 PM, Саша Стаменковић wrote: > > But what if table have no primary key? > > Regards, > Saša Stamenković > > > On Wed, Jun 2, 2010 at 12:53 PM, Hilmar Hallbjörnsson > <[hidden email] <mailto:[hidden email]> > <mailto:[hidden email] <mailto:[hidden email]>>> wrote: > > Hi. > > Normally, what you need in your class is this variable: > > protected $_primary = 'your_primary_key'; OR > > protected $_primary = array( 'primary_1', 'primary_2' > .....); > > This error might occur when the model cannot detect the > primary key, > often it's because you have more than one. > > --Best regards and good luck > Hilmar > > 2010/5/25 zamanphp <[hidden email] > <mailto:[hidden email]> <mailto:[hidden email] > <mailto:[hidden email]>>> > > > > hi all > I'm using Zend_Cachefor Zend_Db_Table_Abstract > Sometimes Htay following occurs: > "A table must have a primary key, but none was found" > While I'm have in the my table primary key. > and Refresh the page to be resolved > What Is Problem؟ > > -- > View this message in context: > http://zend-framework-community.634137.n4.nabble.com/Zend-Db-Table-Exception-A-table-must-have-a-primary-key-but-none-was-found-tp2230044p2230044.html > Sent from the Zend DB mailing list archive at > Nabble.com. > > > > > > |
|
I'd say that in a properly designed database, nearly any table should have a primary key of some sort. 80/20 seems to be a bit too low, I'd say that 99% of the tables will can have a primary key.
The only reason there should be no primary key is when it is perfectly okay to have duplicate records. In most cases, people will still add an extra column with an auto incrementing id. You could also create a primary key on all columns. Also, if you have an UNIQUE index, you can promote that to be the primary key (in MySQL you can only do that when the columns are NOT NULL, but you could also specify the UNIQUE index in PHP). Vincent de Lau [hidden email] > -----Oorspronkelijk bericht----- > Van: Petar Dzhambazov [mailto:[hidden email]] > Verzonden: woensdag 2 juni 2010 14:03 > Aan: Саша Стаменковић > CC: [hidden email] > Onderwerp: Re: [fw-db] Zend_Db_Table_Exception : "A table must have a > primary key, but none was found" > > It is probably the 80/20 % rule. Most of the time your tables will have > primary keys and when they don't they are some sort of special case. > Then you either work with adapter methods or extend Zend_Db_Table to > fit > your case. > > regards > Petar > > On 06/02/2010 02:52 PM, Саша Стаменковић wrote: > > Ah, probably to keep find() method satisfied. > > > > Regards, > > Saša Stamenković > > > > > > On Wed, Jun 2, 2010 at 1:51 PM, Саша Стаменковић <[hidden email] > > <mailto:[hidden email]>> wrote: > > > > Then I don't see the reason for Zend_Db_Table to throw exception. > > Might that be a bug? > > > > Regards, > > Saša Stamenković > > > > > > > > On Wed, Jun 2, 2010 at 1:49 PM, Petar Dzhambazov > <[hidden email] > > <mailto:[hidden email]>> wrote: > > > > Hi, > > If you set > > > > protected $_primary = 'your_primary_key'; > > > > it is not being checked if it is really the private key. So > if > > it fits your needs you can set any filed of the table to be > used > > as primary key. > > > > regards > > Petar > > > > > > On 06/02/2010 02:19 PM, Саша Стаменковић wrote: > > > > But what if table have no primary key? > > > > Regards, > > Saša Stamenković > > > > > > On Wed, Jun 2, 2010 at 12:53 PM, Hilmar Hallbjörnsson > > <[hidden email] <mailto:[hidden email]> > > <mailto:[hidden email] <mailto:[hidden email]>>> > wrote: > > > > Hi. > > > > Normally, what you need in your class is this > variable: > > > > protected $_primary = 'your_primary_key'; OR > > > > protected $_primary = array( 'primary_1', 'primary_2' > > .....); > > > > This error might occur when the model cannot detect > the > > primary key, > > often it's because you have more than one. > > > > --Best regards and good luck > > Hilmar > > > > 2010/5/25 zamanphp <[hidden email] > > <mailto:[hidden email]> <mailto:[hidden email] > > <mailto:[hidden email]>>> > > > > > > > > hi all > > I'm using Zend_Cachefor Zend_Db_Table_Abstract > > Sometimes Htay following occurs: > > "A table must have a primary key, but none was found" > > While I'm have in the my table primary key. > > and Refresh the page to be resolved > > What Is Problem؟ > > > > -- > > View this message in context: > > http://zend-framework- > community.634137.n4.nabble.com/Zend-Db-Table-Exception-A-table-must- > have-a-primary-key-but-none-was-found-tp2230044p2230044.html > > Sent from the Zend DB mailing list archive at > > Nabble.com. > > > > > > > > > > > > |
|
I would go even stronger: 100% of tables must have a primary key. In
some respects, a table isn't a table if it has no primary key constraint. In mathematics, it's the difference between a set and a bag -- a bag permits duplicates, whereas a set doesn't. Relational database tables should be like sets, where each row in the table represents in a fact or statement. C. J. Date said, "once you know a fact, stating it again doesn't make it any more true." To which a student replied, "you can say that again!" Practically, a primary key is the means to address individuals rows, for example the find() method and the save() method assume they can map Row objects in your PHP code to rows in the database using a primary key. All tables must have a primary key to be used in the ORM framework. That's why if you declare no primary key in your Zend_Db_Table class, and it can't discover the primary key by querying metadata, it throws an exception. If you have a table with no primary key constraint, SQL permits this, but you'll have to write the SQL yourself instead of using Zend_Db_Table methods. Regards, Bill Karwin On Jun 2, 2010, at 5:48 AM, Vincent de Lau wrote: > I'd say that in a properly designed database, nearly any table > should have a primary key of some sort. 80/20 seems to be a bit too > low, I'd say that 99% of the tables will can have a primary key. |
|
What about anonymous survey data? I want to fill a table with answers from a questionaire where the user can opt to store them anonymously. So I would not want a required primary key as the intention is NOT to find anything afterwards, I just need summary statistical info. Please correct me if I am wrong.
If not, is there a way to enable the primary key check (apart from extending the class)? |
|
Hello,
2011/6/23 zensys <[hidden email]> > What about anonymous survey data? I want to fill a table with answers from > a > questionaire where the user can opt to store them anonymously. So I would > not want a required primary key as the intention is NOT to find anything > afterwards, I just need summary statistical info. Please correct me if I am > wrong. > > If not, is there a way to enable the primary key check (apart from > extending > the class)? > You just can insert a technical primary key with autoincrement/serial as a new column. Greetings Chris |
| Powered by Nabble | Edit this page |
