[6.x]: Lazy eager loading returns nothing for a multi-instance relation field once its value was read
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 68/100
Hướng nghiên cứu
Bắt đầu từ BaseRelationField::getEagerLoadingMap() và so sánh cách nó đọc các điều kiện truy vấn với normalizeValueForInput(), hàm sử dụng getWhereForColumn('elements.id') và khóa values. Kiểm tra cách biểu diễn điều kiện whereIn() của giá trị đã chuẩn hóa, sau đó chạy hoặc bổ sung kiểm thử cho tình huống trường Assets có nhiều phiên bản. Công việc hoàn tất khi lazy eager loading trả về asset cho một trường đã được đọc trên các mục trong tập kết quả có nhiều mục.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
What happened?
An entry type has one Assets field placed twice in its layout (image, and logoOverHero as a second instance with its own handle). In a site template, {{ element.image.one() }} returns null when element came from a result set of two or more entries (e.g. the nested entries of a Matrix field), although the entry has an image (element.image.ids() returns it, and so does element.image.eagerly(false).one()).
BaseRelationField::getEagerLoadingMap() reads the target IDs from a normalized value's elements.id where with $where['value'], but normalizeValue() adds that constraint with whereIn(), which Laravel stores under values (getQuery()->wheres holds ['type' => 'In', 'column' => 'elements.id', 'values' => [...]]). So the IDs of every source element whose field was already normalized are lost. For single-instance fields fetchRelationsFromDbTable() covers this by querying the relations table, which hides the bug; for multi-instance fields it returns false by design, so the map comes back empty and the element gets an empty eager-loaded result. The element that triggers lazy eager loading always has a normalized value (reading the field is what runs the query), so it always loses its own relations.
The same file reads the same where correctly in normalizeValueForInput() ($value->getWhereForColumn('elements.id') and $where['values']).
Steps to reproduce
- Create an Assets field and add it twice to an entry type's field layout (second instance with a different handle).
- Add two or more entries of that type to a Matrix field on a page; give the first one an image in the first instance.
- In the page's site template:
{% for block in entry.myMatrix.all() %}{{ block.image ? block.image.one().id ?? 'null' }}{% endfor %}.
Expected behavior
The asset ID, as with block.image.eagerly(false).one() or with a single-instance field.
Actual behavior
null (block.image.all() is empty). Changing $where['value'] to $where['values'] in BaseRelationField::getEagerLoadingMap() fixes it.
Craft CMS version
6.x-dev (603f0e0, 2026-10-31)
PHP version
8.5
Operating system and version
macOS (Laravel Herd)
Database type and version
MySQL 8
Image driver and version
—
Installed plugins and versions
None needed to reproduce.
- Ngôn ngữ chính
- PHP
- Star
- 3.6k
- Fork
- 710
- Merge trung bình
- 12 giờ 44 phút
- Pull request đã merge (30 ngày)
- 335
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của craftcms/cms
-
bug repo:cms
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
craftcms/cms#20205 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[6.x]: Element index View menu: sort direction buttons only update after the table has loadedĐang mởbug repo:cms
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
craftcms/cms#20203 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[5.x]: Moving an asset with “Replace it” throws TypeError: volumeUid must be of type string, null givenCó thể đã có người làm @i-just đã nhận 3 ngày trước. Đang mởbug repo:cms
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
craftcms/cms#20128 · 2 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
repo:cms
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 72/100
craftcms/cms#20234 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug repo:cms
Độ khó 4/5 1-2 ngày Mức phù hợp với người mới 55/100
craftcms/cms#20226 · 1 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
Maintainer thường phản hồi trong vòng 1 ngày
-
good first issue level: 1 ui
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 94/100
BeyondITL/contentine-create#58 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
MagnaCapax/PMSS#1224 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
[Bug]: Table search with "REGEXP ^...$" and a value like cat|dog also returns catalog and bulldogĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
phpmyadmin/phpmyadmin#20601 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Hand-built AdminModules URL in DisplayBackOfficeHeader.php (line 36), flagged for PrestaShop 9Đang mở
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 78/100
PrestaShopCorp/ps_accounts#677 ·