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

    I’m using xpdo for a new project using ModX0.9.5. I’m having problems updating agreggates and composites.... how can I change a foreign key ? I’ve tried set("relation_id",$newId) but since the sql produces something like:

     ... SET `relation_id` = :relation_id,`id` = :id WHERE `relation_id` = :relation_id AND ... 


    I’m not sure how this is suposed to work, since we have two different values for the same binding!

    Using addOne($relation) produces:

     ... SET `id` = :id WHERE `relation_id` = :relation_id AND .. 


    which just doesn’t update the relation_id at all...

    Am I doing something wrong ?

    Thanks in advance for your help...
    • Using addOne should update the relation_id, assuming your aggregate or composite relation is defined properly. Can you provide a little more context for the situation?
        • 17906
        • 18 Posts
        I have a simple table to relate fathers with childs. I’m trying to change a child’s father.... this is what I have in my schema :

         <object class="ChildDonation" table="pp_child_donation" extends="xPDOObject">
        	     <field key="father_id" dbtype="int" precision="9" phptype="integer" null="false" default="0" index="pk" />
        	     <field key="child_id" dbtype="int" precision="9" phptype="integer" null="false" default="0" index="pk" />
                <composite class="Father" key="id" local="father_id" foreign="id" cardinality="one" />
                <composite class="Child" key="id" local="child_id" foreign="id" cardinality="one" />
        </object>
        


        This is what I get using addOne($father)

        UPDATE `modx_tese`.`pp_child_donation` SET `id` = :id WHERE `father_id` = :father_id AND `child_id` = :child_id AND `id` = :id LIMIT 1
        
        • First, because you are defining those as composites, any time you delete a record there, it will delete the Father and Child records as well, is that intended?

          Second, you are creating an intersection table with compound primary keys defined. The relations like you are trying to use will currently fail because you can’t use a named parameter twice in a query (that needs to be refactored to use ? parameters for the prepared statements) as you pointed out, and because there are some other defects in the save() method which will be resolved in the beta release coming this week.
            • 17906
            • 18 Posts
            I do not intent to use a composite primary key. I only need the ID to act as primary key. How can I change the schema to reflect this?
            I need to get this working by tomorrow... so any tips are welcome.

            • Quote from: MaDrense at Mar 11, 2007, 04:36 PM

              I do not intent to use a composite primary key. I only need the ID to act as primary key. How can I change the schema to reflect this?
              I need to get this working by tomorrow... so any tips are welcome.
              I’m confused then, because there is no id column defined on this table?
                • 17906
                • 18 Posts
                Wow,

                I feel eally dumb. I copy-pasted the aggregates from the modx schema and didn’t notice the index="pk". I’m extending XPDOSimpleObject so I don’t have to map the id rigth ? I got it working now. Sorry for the mess tongue