model relationship naming

edited May 2014 in Feature Requests
Is there a way to name the property of a foreign_key item? For instance, I have a DB table with a field called loc_parent_fk which is a self-referencing relationship. When I have a record from this model I can't see how to access the related object. I can access $record->loc_parent_fk but that just gives me the id of the related record, I want the object. Typically, if I had a field called category_id that was the identifier for a foreign key then when referencing it within a record (such as $record->category) would yield the related object.


  • edited 1:27AM
    If you are using the foreign_keys property on the model, it requires it to have the suffix of "_id" to automatically work. You can always set up a property in your record model to lazy load in the object like so:
    function loc_parent() { return $this->lazy_load(array('id' => $this->id), 'my_model'); }
  • edited 1:27AM
    I'll give that a shot, I thought it was an issue since in the admin view it was pulling the data from other foreign keys that didn't have the "_id" suffix. Thanks.
Sign In or Register to comment.