We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24719
    • 194 Posts
    hi,

    i’ve been getting the following error when I try to update an existing record:

    No primary key value found for pk definition:


    I’m pretty stumped. I think I’ve left something out of the schema, but can’t see what it is. The schema for this table is:

    <object class="PriceOverride" table="price_override" extends="xPDOSimpleObject">
    		<field key="property" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="" index="index" />
    		<field key="item" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="true" />
    		<field key="num_months" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="true" />
    		<field key="let_full_let" dbtype="enum" precision="'L','FL'" phptype="string" null="true" />
    		<field key="price" dbtype="decimal" precision="8,2" phptype="integer" null="false" default="" />
    		<aggregate class="Property" key="id" local="property" foreign="id" cardinality="one" />
    		<aggregate class="Items" key="id" local="item" foreign="id" cardinality="one" />
    		<aggregate class="NumMonths" key="id" local="num_months" foreign="id" cardinality="one" />
    	</object>


    and the SQL for the table structure is:

    CREATE TABLE `pfp_price_override` (
      `id` int(10) unsigned NOT NULL auto_increment,
      `property` int(10) unsigned NOT NULL,
      `item` int(10) unsigned default NULL,
      `num_months` int(10) unsigned default NULL,
      `let_full_let` enum('L','FL') default NULL,
      `price` decimal(8,2) NOT NULL,
      PRIMARY KEY  (`id`),
      KEY `property` (`property`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Stores details of prices that have been overridden.' AUTO_INCREMENT=9 ;


    I’m still not entirely sure where to define primary keys. This is bizarre since I’ve got other tables working fine. I can retrieve objects and update values, but I just can’t save the changes back to the db.

    **edit**
    I can retrieve values using a composite key such as:
    $xpdo->getObject(’PriceOverride’, array(’property’ => intval($_POST[’id’]), ’num_months’ => intval($monthID[1])))

    but not on the primary key with:
    $po = $xpdo->getObject(’PriceOverride’, $id);

    Thanks for any help

    ps - i’m using xpdo alpha 16 (and don’t really want to upgrade)
      • 22303 MODX Staff
      • 10,725 Posts
      I don’t see any reason for the error. Have you tried outputting the $xpdo->errorInfo() or setting $xpdo->setDebug(true) to get additional output?
        • 24719
        • 194 Posts
        yes, i got the error message with debug set to true. hmm, perhaps i will have to upgrade to see if that solves the problem...

        thanks anyway
          • 24719
          • 194 Posts
          jason, what’s the latest version i can upgrade to without having to follow the steps for the beta upgrade?
            • 22303 MODX Staff
            • 10,725 Posts
            Get revision 35; that was the last revision before the 1.0 beta commits started. I’ll package this up, and offer it as a replacement download for revision 16 when I get a moment.

            BTW, did you make sure your map file matches your schema? i.e. Did you regenerate your maps after any recent changes to the schema?
              • 24719
              • 194 Posts
              thanks. yes, i’d regenerated my maps.

              oh, by the way, i’ve made a few changes to maketable to improve paging. where can i contribute the code? shall i upload the file or just a diff?
                • 22303 MODX Staff
                • 10,725 Posts
                Quote from: redman at Apr 13, 2007, 09:28 AM

                thanks. yes, i’d regenerated my maps.
                Hmmm, haven’t ever seen this before. Are you able to use the primary key method to retrieve any rows from any table in your model (i.e. is it just this table exhibiting this problem)?

                Quote from: redman at Apr 13, 2007, 09:28 AM

                oh, by the way, i’ve made a few changes to maketable to improve paging. where can i contribute the code? shall i upload the file or just a diff?
                You can offer the file here or email me the file, either way. I’m actually going to be moving MakeTable and MakeForm to the MODx model and out of xPDO itself, because they both actually depend on MODx for usage anyway.
                  • 24719
                  • 194 Posts
                  files attached.

                  i’ve only noticed it in this table. One of the other tables has a similar problem except I can retrieve those objects, but there’s a problem saving them back to the db again.

                  What’s weird is that i can retrieve the objects if i specify an array of non-primary keys. The getPrimaryKey method returns the following with debug on:

                  (DEBUG) No primary key value found for pk definition: pk:
                    • 24719
                    • 194 Posts
                    i’ve found a fix. if i add the primary column to the schema, xpdo works. i’ve just added:

                    <field key="id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" index="pk" generated="native" />


                    to the definition for that table.
                      • 22303 MODX Staff
                      • 10,725 Posts
                      Quote from: redman at Apr 14, 2007, 05:30 AM

                      i’ve found a fix. if i add the primary column to the schema, xpdo works. i’ve just added:

                      <field key="id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" index="pk" generated="native" />


                      to the definition for that table.
                      It should have been inherited from xPDOSimpleObject though, so I’m confused...according to your schema anyway huh