Score:2

Programmatically find out field name of an Id-field

ธง cn

Depending on the type of entity, it is either nid/vid/uid and possibly other. It is nice to have an ->id() method which allows you to work with data in an uniform fashion without relying on those details, but there are quite some use-cases, where I am running into troubles.

Just an example, getting list of revision ids for an generic entity seems not possible without knowing the name of the id-field.

$entityTypeId = $entity->getEntityTypeId();
$entityId = $entity->id();

$typeStorage = \Drupal::entityTypeManager()->getStorage($entityTypeId);

$query = $typeStorage->getQuery();
$query->allRevisions();
$query->condition("??????", $entityId);
cn flag
ไม่สามารถทดสอบได้ในขณะนี้ แต่ลอง `$id_field = $entity->getKey('id');`
Score:3
ธง in

EntityType มีฟังก์ชันเพื่อรับคีย์ฟิลด์: EntityType::getKeys. ผลลัพธ์คืออาร์เรย์และ รหัส คีย์ระบุชื่อคุณสมบัติของเขตข้อมูลหลัก

ดู https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21EntityType.php/function/EntityType%3A%3AgetKeys

โพสต์คำตอบ

คนส่วนใหญ่ไม่เข้าใจว่าการถามคำถามมากมายจะปลดล็อกการเรียนรู้และปรับปรุงความสัมพันธ์ระหว่างบุคคล ตัวอย่างเช่น ในการศึกษาของ Alison แม้ว่าผู้คนจะจำได้อย่างแม่นยำว่ามีคำถามกี่ข้อที่ถูกถามในการสนทนา แต่พวกเขาไม่เข้าใจความเชื่อมโยงระหว่างคำถามและความชอบ จากการศึกษาทั้ง 4 เรื่องที่ผู้เข้าร่วมมีส่วนร่วมในการสนทนาด้วยตนเองหรืออ่านบันทึกการสนทนาของผู้อื่น ผู้คนมักไม่ตระหนักว่าการถามคำถามจะมีอิทธิพลหรือมีอิทธิพลต่อระดับมิตรภาพระหว่างผู้สนทนา