Having issues with get_related_keys after upgrade from Fuel 1.2 to 1.4


I had the following function which was working correctly in 1.2:

public function get_case_study_from_slug($slug)
        $query = $this->db->get_where(self::$DB_TABLE, ['slug' => $slug], 1, 0)->result();

        if (!sizeof($query)) return null;

        $query = $query[0];

        $pty_keys = $this->get_related_keys(['id'=>$query->id], ['products']);

        if ($pty_keys) $products = $this->db->where_in('id',$pty_keys)->get('products')->result();
        else $products = [];

        $query->products_they_use = $products;

        return $query;

Now I'm receiving the error: "Message: Too few arguments to function MY_Model::get_related_keys(), 2 passed in .../Case_studies_model.php on line 590 and at least 3 expected"

After comparing the function in 1.2 and 1.4, I can see an additional parameter is expected ($related_field), but it's unclear based on the documentation what that should be https://docs.getfuelcms.com/libraries/my_model#func_get_related_keys -- it looks like the documentation is maybe written wrong, and there is no "example" in the example box.

I kind of inherited this old code from a previous developer...so any direction or advice here would be helpful.


  • The doc block for that method does need to be updated. You are correct that get_related_keys() needs a third parameter which is the related model (e.g. 'Case_studies_model`)

  • Actually...v1.2 had $related_model and that's what the former developer was using ['products'] for there I believe...and that was working. The thing that seems to be missing in his call is $related_field -- which is the newly added first parameter (not sure if it was in 1.3 or 1.4) in get_related_keys() -- maybe I'm overlooking something really simple here...but I'm honestly not sure what that value should be based on his code.

  • The $related_field should be the key of the relationship that's assigned in the model's $has_many property. So hypothetically, there may be a has_many relationship defined in the model (near the top) with the key of case_studies:

    public $has_many = array('case_studies' => 'Case_studies_model');
  • Yeah, found this at the top:

    public $has_many = [
            'filter_subjects' =>
                    'model' => 'subjects_model'
            'products_they_use' =>
                    'model' => 'products_model'

    I assume it's probably the "products_they use" key...will give that a shot and let you know. Cheers.

  • Yep...that seems to have done the trick. You're a lifesaver. Inheriting old code with very few comments is a fun ride, haha ;-)

  • No problem... I know how that is (and have been on the guilty party side as well).

Sign In or Register to comment.