📍 المقالة الرئيسية: Directus 2026.
قبل كتابة كود frontend، نمذجة collections بشكل صحيح يوفر أسابيع من إعادة الهيكلة.
المتطلبات
Directus في الإنتاج. فهم أساسيات SQL. المستوى: متوسط. الوقت: 1-2 ساعة.
الخطوة 1 — خطة النموذج
لـ marketplace صناعة تقليدية إفريقية: Products، Categories، Variants، Brands، Vendors، Tags، Reviews.
الخطوة 2 — Collection Products
Settings → Data Model → Create Collection: products.
id(UUID auto).status(Select: draft، published، archived).name(Input، required، unique).slug(Input، unique، regex slug).description(WYSIWYG).price(Decimal، required).currency(Select: XOF، MAD، TND، EUR، default XOF).stock(Integer، default 0).images(Files، Multiple).category(Many-to-One → categories).brand(Many-to-One → brands).tags(Many-to-Many → tags).
الخطوة 3 — Collection Categories (هرمية)
للفئات نوع Mode → نساء → فساتين:
name(Input).slug(Input، unique).parent(Many-to-One → categories، self-reference).children(One-to-Many → categories، alias).
الخطوة 4 — Collection Variants
للمنتجات بمقاسات/ألوان:
product(Many-to-One → products).size(Select: XS, S, M, L, XL).color(Input).price_adjustment(Decimal).stock(Integer).sku(Input، unique).
الخطوة 5 — Many-to-Many: products_tags
Directus ينشئ تلقائياً الـ junction table.
الخطوة 6 — حقول multilingue (translations)
للمغرب/تونس/الجزائر تخدم FR + AR:
- Field type: Translations.
- Languages: FR، AR، EN.
- الحقول المُترجَمة: name، description، slug.
الخطوة 7 — تحققات metier
Field price: Validation type → Number → min: 0. Slug: Regex ^[a-z0-9-]+$.
الخطوة 8 — Computed fields
// Field type: Custom (formula)
{{ price | format_currency(currency) }}
الخطوة 9 — صلاحيات لكل حقل
Role Editor: يمكنه update name، description، price، images. لا يمكنه update status (Reviewer فقط).
الخطوة 10 — اختبار API
curl https://cms.votre-entreprise.com/items/products?fields=*,category.name,brand.name,images.*&filter[status][_eq]=published
الأخطاء الشائعة
| الخطأ | الحل |
|---|---|
| M2M لا يعمل | أعد إنشاء field عبر Studio |
| Translations فارغة | قدم دائماً النسخة الافتراضية |
| Slug مكررات | فعّل unique |
| Performance N+1 | ?fields=*,relation.* |
التكيف مع السياق
Multi-currency XOF، MAD، TND، EUR. Marketplaces multi-vendeurs: vendor as collection. Tags transverses: «bio»، «artisanal»، «fait main».
دروس الإخوة
الأسئلة المتكررة
Migrations schema في الإنتاج؟ Studio يولد migrations Knex.js.
الأداء مع 1M items؟ Indexes على foreign keys + status + slug.