Model foreign keys?

edited August 2011 in Modules
So I've been working on a project for a week or so now and I'm starting to like Fuel but I really don't understand how it all comes together. I have a model for user bios which has to be associated with a user. Needless to say adding a foreign key of 'user_id' worked like a charm but I don't understand how it worked and how I could reproduce it in my own models and associative models.

Also as long as we're on the subject I'd like to know if there's a way i could possibly exclude certain results like the administrator account or already existing associations.

Thanks again.


  • edited 2:21AM
    $foreign_keys are used in 2 spots in the fuel/application/core/MY_Model.php file. The first is in the form_fields method, where it will create the drop down select for you (otherwise it would just be a text field by default). The other place $foreign_keys is used is in the record specific object. It will automatically load that object using the __get method (see around line 2985 in MY_Model).

    With regards to your second question about excluding certain results, if you are wanting to do it in your selects, you can use $this->db->select('my_field1, my_field3...'); before you do your $this->my_model->find_.... method (CI active record can be used along with you model queries). If you are wanting to exclude those fields from the form, you can do an unset($fields['my_field1'); in your form_fields() method.
Sign In or Register to comment.