Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add relationships support for grids #65

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ahebrank
Copy link

@ahebrank ahebrank commented Oct 5, 2018

Relationship fields within grids aren't followed down the rabbit hole to fetch the child_id out of the separate relationship table. This adds that relationship lookup (with caching like the existing lookups).

@Zignature
Copy link

Fixed some bugs:

  • This doesn't work when multiple grid fields with a relationships column exist in the channel entry. Only the first grid field will get relationships returned.
    Took out lines 513, 514 and 537 to fix this.

  • Lines 523 - 526 are duplicated on lines 528 - 531.
    Removed duplicate lines 528 - 531

protected function entries_grid_relationship($grid_col_id, $grid_row_id, $entry_id)
{
  $query = ee()->db->select('parent_id, child_id, grid_field_id, grid_col_id, grid_row_id, field_id, fluid_field_data_id')
                   ->where_in('parent_id', $this->entries_entry_ids)
                   ->where('grid_col_id', $grid_col_id)
                   ->order_by('order', 'asc')
                   ->get('relationships');

  foreach ($query->result_array() as $row)
  {
    if ( ! isset($this->entries_grid_relationship_data[$grid_col_id][$row['parent_id']][$row['grid_row_id']]))
    {
      $this->entries_grid_relationship_data[$grid_col_id][$row['parent_id']][$row['grid_row_id']] = array();
    }

    $this->entries_grid_relationship_data[$grid_col_id][$row['parent_id']][$row['grid_row_id']][] = (int) $row['child_id'];
  }

  $query->free_result();

  if (isset($this->entries_grid_relationship_data[$grid_col_id][$entry_id][$grid_row_id]))
  {
    return $this->entries_grid_relationship_data[$grid_col_id][$entry_id][$grid_row_id];
  }

  return array();
}

@Zignature
Copy link

Fixed some bugs:

  • This doesn't work when multiple grid fields with a relationships column exist in the channel entry. Only the first grid field will get relationships returned.
    Took out lines 513, 514 and 537 to fix this.
  • Lines 523 - 526 are duplicated on lines 528 - 531.
    Removed duplicate lines 528 - 531
protected function entries_grid_relationship($grid_col_id, $grid_row_id, $entry_id)
{
  $query = ee()->db->select('parent_id, child_id, grid_field_id, grid_col_id, grid_row_id, field_id, fluid_field_data_id')
                   ->where_in('parent_id', $this->entries_entry_ids)
                   ->where('grid_col_id', $grid_col_id)
                   ->order_by('order', 'asc')
                   ->get('relationships');

  foreach ($query->result_array() as $row)
  {
    if ( ! isset($this->entries_grid_relationship_data[$grid_col_id][$row['parent_id']][$row['grid_row_id']]))
    {
      $this->entries_grid_relationship_data[$grid_col_id][$row['parent_id']][$row['grid_row_id']] = array();
    }

    $this->entries_grid_relationship_data[$grid_col_id][$row['parent_id']][$row['grid_row_id']][] = (int) $row['child_id'];
  }

  $query->free_result();

  if (isset($this->entries_grid_relationship_data[$grid_col_id][$entry_id][$grid_row_id]))
  {
    return $this->entries_grid_relationship_data[$grid_col_id][$entry_id][$grid_row_id];
  }

  return array();
}

This doesn't seem to work either... :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants