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

Keep manual reorder on fields links #44

Open
KillianLeroux opened this issue Sep 15, 2020 · 2 comments
Open

Keep manual reorder on fields links #44

KillianLeroux opened this issue Sep 15, 2020 · 2 comments

Comments

@KillianLeroux
Copy link

Hello, it's me (again :) ).

I have a new problem:

My records have several fields with type "Link to another record", and I would like keep the manual reorder when I retrieve them, but this isn't the case today :'(

The manual reorder explanation: https://support.airtable.com/hc/en-us/articles/217521267

I started to research where the problem comes from and I viewed that related_field are retrieved by a new API call with a filterByFormula on RECORD_ID() in OR, example:

OR(RECORD_ID() = 'recdpDDhXpoZOhvny', RECORD_ID() = 'recNwuDQa3evOLZnm')

The full API call:
https://api.airtable.com/v0/app75XXX/Team%20Members?filterByFormula=OR%28RECORD_ID%28%29+%3D+%27recdpDDhXpoZOhvny%27%2C+RECORD_ID%28%29+%3D+%27recNwuDQa3evOLZnm%27%29

So the sort order is lost here, because the API return records without considering the sort order in parent table :/

@KillianLeroux
Copy link
Author

KillianLeroux commented Sep 17, 2020

So I found a solution, I wanted create a pull request but no permissions :'(

I add this code in Response.php after while( $relation_request = $relation_response->next() ); in line 162:

// Keep order
if (count($relation_ids) > 1) {
    $related_records_sorted = array();

    foreach ($relation_ids as $relation_id) {
        $key = array_search($relation_id, array_column($related_records, 'id'));

        if ($key !== false) {
            $related_records_sorted[] = $related_records[$key];
        }
    }

    $related_records = $related_records_sorted;
}

Can you push this code if it's ok for you please? =p

@KillianLeroux
Copy link
Author

FYI I updated the code to remove the unset.

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

No branches or pull requests

1 participant