# 플러그인이 HasCustomFields::NotPreloadedError를 표시합니다

**URL:** https://meta.discourse.org/t/the-plugin-shows-hascustomfields-notpreloadederror/329999
**Category:** Development
**Created:** [10월 9, 2024, 2:10오전 UTC](https://meta.discourse.org/t/the-plugin-shows-hascustomfields-notpreloadederror/329999 "2024-10-09T02:10:36Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![zhanfeng](https://avatars.discourse-cdn.com/v4/letter/z/f1d935/32.png) [@zhanfeng](https://meta.discourse.org/u/zhanfeng)
#### Post date: [10월 9, 2024, 2:10오전 UTC](https://meta.discourse.org/t/the-plugin-shows-hascustomfields-notpreloadederror/329999/1 "2024-10-09T02:10:36Z")

</div>

code:

```plaintext
field = 'video_url'
register_post_custom_field_type(field, :string)
register_topic_custom_field_type(field, :string)
add_preloaded_topic_list_custom_field(field)

add_to_serializer(:topic_list_item, field.to_sym) { object.custom_fields[field] }

add_to_serializer(:topic_view, field.to_sym) { object.topic.custom_fields[field] }

add_to_serializer(:search_topic_list_item, field.to_sym) { object.custom_fields[field] }

```

검색 목록에서 커스텀 필드를 반환하도록 플러그인에 코드를 추가했는데, 예외가 발생했습니다. 추가한 코드는 다음과 같습니다:

```plaintext
add_to_serializer(:search_topic_list_item, field.to_sym) { object.custom_fields[field] }

```

에러:

```plaintext
HasCustomFields::NotPreloadedError (Attempted to access the non preloaded custom field 'video_url' on the 'Topic' class. This is disallowed to prevent N+1 queries.) app/models/concerns/has_cus

```

이 문제를 경험해 보신 분이 계신가요? 도움을 주시면 정말 감사하겠습니다.
