Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Relationships without having to use Primary Key?
  • Hi, Is it possible to define a relationship (has_one) without having to use the Primary Key? For example Table 1: Business
    ==============
    id : int
    name : varchar
    postal_address_id : int <-- this will reference the table "Postal Address" Table 2: User
    ===========
    id : int
    name : varchar
    postal_addrress_id : int <-- this will also reference the "Postal Address" table Table 3: PostalAddress
    ===================
    id : int
    street1 : varchar
    town : varchar
    postcode : varchar
    geo_long : float
    geo_lat : float Essentially I want to have a single Table / Model which has Postage and Map related functions which is maintained separately to the Business and User tables. Every User and ever Business has there own record in the Postal Address table and duplicate addresses are allowed. Makes life easier when a user moves location. I've tried defining the relationship on both the Business and User models as: protected static $_has
    'postal_address' => array(
    'key_from' => 'postal_address_id',
    'model_to' => '\\CoreContent\\Model_PostalAddress',
    'key_to' => 'id',
    'cascade_save' => true,
    'cascade_delete'=> true
    )
    ); However, although it will go ahead and save both models the "postal_address_id" column is left as "Null" and not being set to the ID of the PostalAddress model which gets stored. I've no need to be able to go back from the postal address table to the parent model which is based at said address. I've been through some of the ORM code but can't figure out what I might want to change to get my desired functionality working and would really rather find a FuelPHP way of doing this rather than replacing the class(es).
    Thanks, Richard

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!