On Dec 13, 1:33 pm, WebbedIT <p...@webbedit.co.uk> wrote:
> > Is it correct to associate my models such that:
>
> > commercial_vendor belongsTo vendor
> > organizational_vendor belongsTo vendor
>
> Yes, in the first application I am working on with CakePHP I have the
> following tables
>
> organisations
> people
> agencies
> households
> schemes
> agency_contacts
> clients
> staff
>
> I have created the belongsTo relationships as follow:
>
> Agency, Household and Scheme belongsTo => 'Organisation'
> AgencyContact, Client, Staff belongsTo => 'Person'
>
> And the reverse hasOne relations:
>
> Organisation hasOne => array('Agency', 'Household', 'Scheme')
> Person hasOne => array('AgencyContact', 'Client', 'Staff')
>

Okay, I guess I'm going to have to take this in bite-sized chunks
because something's not working right (or my expectations are wrong).
I have a vendors table whose PK field is named "id", a
commercial_vendors table whose PK is named "vendor_id" that also has a
FK on "vendor_id" pointing back to the vendors table (it's really more
of an inheritance model: a commercial_vender is-a vendor).  The shared
vendor data also references an address in an address table (PK:id) via
a FK named address_id. Each commercial vendor is of a certain type
(food, educational, etc.). To illustrate, here is my DDL script for
this section of the model:

CREATE TABLE addresses (
        id                                              CHAR(36)                
NOT NULL,
        streetaddress_1                 VARCHAR(255)    NOT NULL,
        streetaddress_2                 VARCHAR(255)    NULL,
        city                                    VARCHAR(255)    NOT NULL,
        state_id                                VARCHAR(255)    NOT NULL,
        zipcode                                 INT                             
NOT NULL,
        PRIMARY KEY ( id )
)
ENGINE=InnoDB;

CREATE TABLE commercial_vendor_types (
        id                      VARCHAR(255)    NOT NULL,
        title           VARCHAR(255)    NOT NULL,
        description     VARCHAR(255)    NULL,
        PRIMARY KEY ( id )
)
ENGINE=InnoDB;

CREATE TABLE vendors (
        id                                              CHAR(36)                
NOT NULL,
        business_name                   VARCHAR(255)    NOT NULL,
        applicant_lastname              VARCHAR(255)    NOT NULL,
        applicant_firstname             VARCHAR(255)    NOT NULL,
        applicant_title                 VARCHAR(255)    NOT NULL,
        phone_number                    INT                             NOT 
NULL,
        address_id                              CHAR(36)                NOT 
NULL,
        created                                 DATETIME                NOT 
NULL,
        modified                                DATETIME                NOT 
NULL,
        PRIMARY KEY ( id ),
        FOREIGN KEY ( address_id )
                REFERENCES addresses ( id )
                        ON DELETE CASCADE
                        ON UPDATE CASCADE
)
ENGINE=InnoDB;

CREATE TABLE commercial_vendors (
        vendor_id                                       CHAR(36)                
NOT NULL,
        commercial_vendor_type_id       VARCHAR(255)    NOT NULL,
        booth_width                                     INT                     
        NOT NULL,
        booth_height                            INT                             
NOT NULL,
        description                                     TEXT                    
NOT NULL,
        prior_participant                       BOOLEAN                 NOT 
NULL,
        PRIMARY KEY ( vendor_id ),
        FOREIGN KEY ( vendor_id )
                REFERENCES vendors ( id )
                        ON DELETE CASCADE
                        ON UPDATE CASCADE,
        FOREIGN KEY ( commercial_vendor_type_id )
                REFERENCES commercial_vendor_types ( id )
                        ON DELETE CASCADE
                        ON UPDATE CASCADE
)
ENGINE=InnoDB;

Given that data structure, here are the relevant models:

class Vendor extends AppModel {

        public $name   = 'Vendor';
        public $hasOne = array ( 'CommercialVendor', 'Address' );

}

class Address extends AppModel {

        public $name      = 'Address';
        /** no relationship defined b/c this will only be edited through a
vendor */
}

class CommercialVendor extends AppModel {

        public $name            = 'CommercialVendor';
        public $primaryKey      = 'vendor_id';
        public $hasOne          = array ( 'CommercialVendorType' );
        public $belongsTo       = array ( 'Vendor' );
}

class CommercialVendorType extends AppModel {

        public $name      = 'CommercialVendorType';
}

I was hoping that Cake's scaffolding would allow me to access
http://servername/commercial_vendors/add and enter:

- The shared vendor data, including an address
- The data specific to commercial vendors
- Select (rather than type) the commercial vendor type

Instead, I see inputs for only the commercial vendor data and a
textbox to enter the vendor type rather than a selectbox or series of
radio buttons.  Have I coded this incorrectly or are my expectations
too high?

Thanks again.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to