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

Issue with creating multipleRecordLinks '0.options.isReversed is missing' #368

Closed
Ledoux opened this issue Apr 20, 2024 · 2 comments
Closed

Comments

@Ledoux
Copy link

Ledoux commented Apr 20, 2024

Hi I want to create a link content.account from a 'contents' table towards the associated account (via the content.accountId field).

When I try to create the link and the reverse link :

linked_field = accounts_table.create_field(
    'contents', 
    'multipleRecordLinks', 
    options={
        'linkedTableId': contents_table.id
    }
)

 contents_table.create_field(
      'account', 
      'multipleRecordLinks', 
      options={
          'inverseLinkFieldId': linked_field.id,
          'linkedTableId': accounts_table.id,
          'prefersSingleRecordLink': True
     }
)

I cannot, I have such issues :

requests.exceptions.HTTPError: ('422 Client Error: Unprocessable Entity for url: https://api.airtable.com/v0/meta/bases/appYDDFYw4ZmrGAa0/tables/tbl3s3YftIiu3G8X5/fields', "{'type': 'INVALID_FIELD_TYPE_OPTIONS_FOR_CREATE', 'message': 'Invalid options for contents.account: Failed schema validation: account.0.options.isReversed is missing, prefersSingleRecordLink is not included in the account.1.options schema'}")

I tried a bit to add all the permutation possibles with isReversed, and inverseLinkFieldId but I m stuck,it would be cooll to have a better understanding of this api please, thanks a lot:)

Best,

@BAPCon
Copy link
Contributor

BAPCon commented Apr 22, 2024

https://community.airtable.com/t5/development-apis/creating-a-table-with-multiplerecordlinks-field-with-rest-api/m-p/157602#M12761

I can't find any working examples of this functionality even from the REST API, in the mean time I would suggest using lookup tables with one field being the primary field:

linked_field1 = table1.create_field(
    'contents', 
    'multipleRecordLinks', 
    options={
        'linkedTableId': table2.id,
    }
)

linked_field2 = table2.create_field(
      'accounts', 
      'multipleRecordLinks', 
      options={
        'linkedTableId': table1.id,
     }
)```

@mesozoic
Copy link
Collaborator

Reading the API documentation for multipleRecordLinks, it looks like the only options they support for creating or updating fields are linkedTableId and viewIdForRecordSelection. The inverseLinkFieldId and prefersSingleRecordLink properties are only available when reading the field metadata.

My understanding of how these fields work is that creating a link field from table1→table2 should automatically create the reciprocal field on table2, which you'd be able to identify by looking at the inverseLinkFieldId property. For example:

>>> created_field = table1.create_field('link', 'multipleRecordLinks', options={'linkedTableId': table2.schema().id})
>>> created_field
MultipleRecordLinksFieldSchema(type='multipleRecordLinks', options=MultipleRecordLinksFieldOptions(is_reversed=False, linked_table_id='tbl...', prefers_single_record_link=False, inverse_link_field_id='fldVIhHyCq5yUbWDb', view_id_for_record_selection=None), id='fld9GFYJfZo8hk1UG', name='link', description=None)
>>> inverse = next(
...     field for field in table2.schema(force=True)
...     if field.type == "multipleRecordLinks"
...     and field.options.inverse_link_field_id = created_field.id
... )
>>> inverse
MultipleRecordLinksFieldSchema(type='multipleRecordLinks', options=MultipleRecordLinksFieldOptions(is_reversed=False, linked_table_id='tbl...', prefers_single_record_link=False, inverse_link_field_id='fld9GFYJfZo8hk1UG', view_id_for_record_selection=None), id='fldVIhHyCq5yUbWDb', name='One', description=None)

I'm going to close this issue since it's not a bug with the pyairtable library. I suggest asking on the Airtable Community Forums if you have follow-up questions or feature requests.

@mesozoic mesozoic closed this as not planned Won't fix, can't repro, duplicate, stale Apr 22, 2024
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

3 participants