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

    Sorry for the basic questions I’m doing.

    The doubts go through the following example;
    1 - The relationship to divide tables
    2 - The date field
    3 - Is it advisable to divide tables?
    4- By extending the class xPDOSimpleObject, should we relate to the user tables?
    <?xml version="1.0" encoding="UTF-8"?>
    <model package="providerstorefinder" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" phpdoc-package="providerstorefinder" phpdoc-subpackage="model">
    <object class="sfStore" table="sfinder_stores" extends="xPDOSimpleObject">
    <field key="name" dbtype="varchar" precision="100" phptype="string" null="false" default="" index="index" />
    <field key="published" dbtype="bool" null="false" default="true" />
    <field key="active" dbtype="int" precision="1" attributes="unsigned" phptype="integer" null="false" default="0" />
    <composite alias="Phone" class="pHones" local="id" foreign="phone" cardinality="many" owner="local" />
    <composite alias="StartEndDate" class="StartEndDates" local="id" foreign="startenddate" cardinality="many" owner="local" />
    </object>
    <object class="provStore" table="provider_stores" extends="xPDOSimpleObject">
    <field key="name" dbtype="varchar" precision="100" phptype="string" null="false" default="" index="index" />
    <field key="published" dbtype="bool" null="false" default="true" />
    <field key="active" dbtype="int" precision="1" attributes="unsigned" phptype="integer" null="false" default="0" />
    <composite alias="Phone" class="pHones" local="id" foreign="phone" cardinality="many" owner="local" />
    <composite alias="StartEndDate" class="StartEndDates" local="id" foreign="startenddate" cardinality="many" owner="local" />
    </object>
    <object class="pHone" table="phone" extends="xPDOSimpleObject">
    <field key="phone" dbtype="varchar" precision="20" phptype="string" null="false" default="" />
    <field key="active" dbtype="int" precision="1" attributes="unsigned" phptype="integer" null="false" default="0" /></object>
    <object class="StartEndDate" table="startenddate" extends="xPDOSimpleObject">
    <field key="StartDate" dbtype="date" precision="14" phptype="string" null="false" default="" />
    <field key="EndDate" dbtype="date" precision="14" phptype="string" null="false" default="" />
    <field key="active" dbtype="int" precision="1" attributes="unsigned" phptype="integer" null="false" default="0" index="index" />
    </object>
    </model>
    
    • Quote from: Mortal at Oct 27, 2009, 07:53 PM

      1 - The relationship to divide tables
      2 - The date field
      3 - Is it advisable to divide tables?
      4- By extending the class xPDOSimpleObject, should we relate to the user tables?
      For 1 & 3, what do you mean by "divide tables"? I am not understanding the question.

      For 2, what about the date field? You should set the phptype="date" as well; this will allow you to format the date using standard date(), strftime(), or RegEx formatting parameters via the API, e.g.
      <?php
      $mdyStartDate = $StartEndDateObj->get('StartDate', '%m-%d-%Y');
      ?>


      For 4, xPDOSimpleObject just predefines a single id column for the table which becomes the primary key. I’m not sure I understand what this has to do with the user table?
        • 20256
        • 49 Posts
        2 - is the answer I was looking through

        1 and 3 - What is better?

        For four or five tables as well (for now)

        a)
        Table storefinder
        id, name, address, city, state, zip, country, phone, fax, select

        Table providerfinder
        id, name, address, city, state, zip, country, phone, fax, select

        Table services
        id, name, address, city, state, zip, country, phone, fax, select
        -----
        Or so, to allow more than one phone, or address of branches.

        b)
        Address table
        id, address, city, state, zip, country

        Phone table
        id, phone

        Table storefinder
        id, name -((with composite relationships to the address and phone tables))-

        Table providerfinder
        id, name -((with composite relationships to the address and phone tables))-

        Table services
        id, name -((with composite relationships to the address and phone tables))-

        4 - To retrieve all records written by the user. Do I create a composite relationship between UserId to these tables?

        5 - (new) Is it necessary to create the relationships in phpMyAdmin?
          • 20256
          • 49 Posts
          Something more for the 4 - Is this relationship is possible?

          <object class="sfStore" table="sfinder_stores" extends="xPDOSimpleObject">
          <field key="name" dbtype="varchar" precision="100" phptype="string" null="false" default="" index="index" />
          <field key="active" dbtype="int" precision="1" attributes="unsigned" phptype="integer" null="false" default="0" />
          <composite alias="Sfinder_Stores_Messages" class="messages" local="id" foreign="modx_user_messages" cardinality="many" owner="local" />
          </object>
            • 20256
            • 49 Posts
            I think they are 2 tables

            Table User_Messages
            modx_usersID
            Sender BusinessID (sfinder_stores or providerfinder)
            Text Messages

            and

            Table Business_Messages
            BusinessID (sfinder_stores or providerfinder)
            Sender modx_usersID
            Text Messages
            • Mortal, have you read this: http://svn.modxcms.com/docs/display/XPDO10/Defining+Relationships ?

              Maybe if you can restate the questions here; I’m having a hard time following exactly what your questions are at this point because the relationships you are showing are not valid in any way. To relate to the user table though you need to define a column in your table with a user field or similar that is a foreign key to the modUser class, e.g.
              <field key="user" dbtype="int" precision="10" phptype="integer" attributes="unsigned" null="false" default="0" index="index" />
              <aggregate alias="User" class="modUser" local="user" foreign="id" cardinality="one" owner="foreign" />

              Then you can define a function to get all the records related to a user, either a global function you include, or as a separate Snippet, or in a class in your model. I generally make a main class for my model with commonly used functions and/or smaller utility classes I load as needed.
                • 20256
                • 49 Posts
                You changed my perspective
                I saw that link but when translated is not understood.

                From the example of http://svn.modxcms.com/docs/display/revolution/Using+Custom+Database+Tables+in+your+3rd+Party+Components

                I need to:
                Each registered user can record many businesses. and these are deleted when you delete the User

                <field key="active" dbtype="int" precision="1" attributes="unsigned" phptype="integer" null="false" default="0" />
                <composite alias="User" class="modUser" local="active" foreign="id" cardinality="many" owner="foreign" />
                Is it right or I still lost?
                • Quote from: Mortal at Oct 30, 2009, 09:41 PM

                  I need to:
                  Each registered user can record many businesses. and these are deleted when you delete the User

                  <field key="active" dbtype="int" precision="1" attributes="unsigned" phptype="integer" null="false" default="0" />
                  <composite alias="User" class="modUser" local="active" foreign="id" cardinality="many" owner="foreign" />
                  Is it right or I still lost?
                  I think you’re still lost a bit. You can’t have a foreign key of user that is an integer of precision 1; the modUser.id column is an integer with precision 10 and your foreign key field must match that.
                    • 20256
                    • 49 Posts
                    I appreciate the patience, I tell him that I advanced a lot since my last post

                    What is not yet finished to resolve is the following:

                    The following example:
                    <object class="modAccessPolicy" table="access_policies" extends="xPDOSimpleObject">
                    <field key="name" dbtype="varchar" precision="255" phptype="string" null="false" index="unique" />
                    <field key="description" dbtype="mediumtext" phptype="string" />
                    <field key="parent" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default="0" index="index" />
                    <field key="class" dbtype="varchar" precision="255" phptype="string" null="false" default="" index="index" />
                    <field key="data" dbtype="text" phptype="json" default="{}" />
                    <aggregate alias="Parent" class="modAccessPolicy" local="parent" foreign="id" owner="foreign" cardinality="one" />
                    <aggregate alias="Children" class="modAccessPolicy" local="id" foreign="parent" owner="local" cardinality="many" />
                    </object>

                    What is the difference between local="parent" and local="id" in this instance?
                    owner="foreign", owner="local" Of what? What that meant?
                    • Quote from: Mortal at Nov 02, 2009, 07:15 PM

                      What is the difference between local="parent" and local="id" in this instance?
                      owner="foreign", owner="local" Of what? What that meant?
                      For Children of the current record, the foreign key is the parent field; so if the foreign ’parent’ equals the local ’id’, this identifies Children in this self-referential relationship. For the current record’s Parent, it’s just the opposite: if the foreign ’id’ equals the local ’parent’, well, then that is the Parent object. Owner means, which side of the relationship owns the key, the foreign entity or the local one.