RelatedParagraph.php 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Factories\HasFactory;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  6. /**
  7. * 段落关联关系(mūla ← aṭṭhakathā ← ṭīkā 的注释对应)。
  8. *
  9. * 底层表 `related_paragraphs`。匹配键是 (book_name, cs_para):相同 book_name + cs_para
  10. * 的段落互为注释关系。book_id 只用于输出书名(对应 book_titles.sn),不参与匹配。
  11. */
  12. class RelatedParagraph extends Model
  13. {
  14. use HasFactory;
  15. protected $table = 'related_paragraphs';
  16. /**
  17. * 相关段落的「真书」:book_id 对应 book_titles.sn(一个 level=1 书 = 一个 sn)。
  18. *
  19. * 没有数据库外键约束(建表时就没有),且 sn 上只有普通索引、不是唯一键——
  20. * 历史数据里同一 sn 可能对应多行,批量查询时用 whereIn('sn') 取。
  21. */
  22. public function bookTitle(): BelongsTo
  23. {
  24. return $this->belongsTo(BookTitle::class, 'book_id', 'sn');
  25. }
  26. }