> ## Documentation Index
> Fetch the complete documentation index at: https://docs.base44.com/llms.txt
> Use this file to discover all available pages before exploring further.

# יצירת Entities

> Entities של Base44 מוגדרים מקומית בפרויקט שלך ואז נדחפים ל-Base44 backend.

<Warning>
  דף זה הוא חלק ממיומנות של סוכן קידוד AI ונכתב לסוכנים, לא לבני אדם. לתיעוד Base44 הקריא לבני אדם, ראה את [תיעוד המפתחים](/developers).
</Warning>

# Creating Entities

Entities של Base44 מוגדרים מקומית בפרויקט שלך ואז נדחפים ל-Base44 backend.

## קריטי: מתן שמות לקבצים

קבצי entity חייבים להשתמש במתן שמות kebab-case: `{kebab-case-name}.jsonc`

| שם Entity     | שם קובץ              |
| ------------- | -------------------- |
| `Task`        | `task.jsonc`         |
| `TeamMember`  | `team-member.jsonc`  |
| `ActivityLog` | `activity-log.jsonc` |

WRONG: `TeamMember.jsonc`, `teamMember.jsonc`
RIGHT: `team-member.jsonc`

## תוכן עניינים

* [Creating Entities](#creating-entities)
  * [Entity Directory](#entity-directory)
  * [How to Create an Entity](#how-to-create-an-entity)
  * [Entity Schema Structure](#entity-schema-structure)
  * [Supported Field Types](#supported-field-types)
  * [Field Properties](#field-properties)
  * [Complete Example](#complete-example)
  * [Naming Conventions](#naming-conventions)
  * [Relationships Between Entities](#relationships-between-entities)
  * [Row Level Security (RLS)](#row-level-security-rls)
  * [Field Level Security (FLS)](#field-level-security-fls)
  * [Pushing Entities](#pushing-entities)

## Entity Directory

כל הגדרות ה-entity חייבות להיות ממוקמות בתיקיית `base44/entities/` בשורש הפרויקט שלך. כל entity מוגדר בקובץ `.jsonc` משלו.

מבנה לדוגמה:

```
my-app/
  base44/
    entities/
      user.jsonc
      product.jsonc
      order.jsonc
```

## איך ליצור Entity

1. צור קובץ `.jsonc` חדש בתיקיית `base44/entities/`
2. הגדר את סכמת ה-entity שלך על פי המבנה למטה
3. דחוף את השינויים ל-Base44 באמצעות ה-CLI

## מבנה סכמת Entity

כל קובץ entity עוקב אחר מבנה דמוי JSON Schema:

```jsonc theme={null}
{
  "name": "EntityName",       // PascalCase entity name
  "type": "object",           // Always "object"
  "properties": {
    // Define your fields here
  },
  "required": ["field1"]      // Array of required field names
}
```

### טעות נפוצה: מאפיין schema מקונן

**שגוי** - אל תעטוף מאפיינים באובייקט `schema`:

```jsonc theme={null}
{
  "name": "Task",
  "description": "A task entity",
  "schema": {                    // ❌ WRONG - don't use nested "schema"
    "type": "object",
    "properties": { ... }
  }
}
```

**נכון** - שים `type` ו-`properties` ברמה העליונה:

```jsonc theme={null}
{
  "name": "Task",
  "description": "A task entity",
  "type": "object",              // ✅ CORRECT - top level
  "properties": { ... }          // ✅ CORRECT - top level
}
```

זו טעות נפוצה שתגרום לשגיאות "Invalid schema: Schema must have a 'type' field" בעת דחיפת entities.

## סוגי שדות נתמכים

### String

שדה טקסט בסיסי:

```jsonc theme={null}
{
  "title": {
    "type": "string",
    "description": "Task title"
  }
}
```

עם format:

```jsonc theme={null}
{
  "due_date": {
    "type": "string",
    "format": "date",
    "description": "Due date"
  }
}
```

Formats זמינים: `date`, `date-time`, `time`, `email`, `uri`, `hostname`, `ipv4`, `ipv6`, `uuid`, `file`, `regex`, `richtext`

### String עם Enum

מוגבל לערכים ספציפיים:

```jsonc theme={null}
{
  "status": {
    "type": "string",
    "enum": ["todo", "in_progress", "done"],
    "default": "todo",
    "description": "Current status"
  }
}
```

### Number

```jsonc theme={null}
{
  "position": {
    "type": "number",
    "description": "Position for ordering"
  }
}
```

### Integer

למספרים שלמים בלבד:

```jsonc theme={null}
{
  "quantity": {
    "type": "integer",
    "description": "Item quantity",
    "minimum": 0,
    "maximum": 1000
  }
}
```

### Binary

לנתוני file/blob:

```jsonc theme={null}
{
  "attachment": {
    "type": "binary",
    "description": "File attachment"
  }
}
```

### Boolean

```jsonc theme={null}
{
  "notify_on_change": {
    "type": "boolean",
    "default": true,
    "description": "Enable notifications"
  }
}
```

### מערך של Strings

```jsonc theme={null}
{
  "labels": {
    "type": "array",
    "items": { "type": "string" },
    "description": "Task labels/tags"
  }
}
```

### מערך של Objects

```jsonc theme={null}
{
  "attachments": {
    "type": "array",
    "description": "File attachments",
    "items": {
      "type": "object",
      "properties": {
        "name": { "type": "string" },
        "url": { "type": "string" },
        "type": { "type": "string" }
      }
    }
  }
}
```

## מאפייני שדה

| מאפיין        | תיאור                                                                                                                    |
| ------------- | ------------------------------------------------------------------------------------------------------------------------ |
| `type`        | סוג נתונים: `string`, `number`, `integer`, `boolean`, `array`, `object`, `binary`                                        |
| `description` | תיאור השדה שקריא לאדם                                                                                                    |
| `enum`        | מערך של ערכים מותרים (עבור strings)                                                                                      |
| `enumNames`   | תוויות קריאות לאדם עבור ערכי enum (אותו סדר כמו `enum`)                                                                  |
| `default`     | ערך ברירת מחדל כשלא מסופק                                                                                                |
| `format`      | רמז לפורמט: `date`, `date-time`, `time`, `email`, `uri`, `hostname`, `ipv4`, `ipv6`, `uuid`, `file`, `regex`, `richtext` |
| `items`       | סכמה לפריטי מערך                                                                                                         |
| `properties`  | מאפיינים מקוננים עבור סוגי object                                                                                        |
| `$ref`        | הפניה להגדרת סכמה אחרת                                                                                                   |
| `minLength`   | אורך string מינימלי                                                                                                      |
| `maxLength`   | אורך string מקסימלי                                                                                                      |
| `pattern`     | תבנית regex לאימות string                                                                                                |
| `minimum`     | ערך מינימלי למספרים                                                                                                      |
| `maximum`     | ערך מקסימלי למספרים                                                                                                      |
| `rls`         | כללי אבטחה ברמת שדה (ראה סעיף Field Level Security)                                                                      |

## דוגמה מלאה

הנה הגדרת entity מלאה עבור Task:

```jsonc theme={null}
{
  "name": "Task",
  "type": "object",
  "properties": {
    "title": {
      "type": "string",
      "description": "Task title"
    },
    "description": {
      "type": "string",
      "description": "Task description"
    },
    "status": {
      "type": "string",
      "enum": ["todo", "in_progress", "done"],
      "default": "todo",
      "description": "Current status of the task"
    },
    "board_id": {
      "type": "string",
      "description": "Board this task belongs to"
    },
    "assignee_email": {
      "type": "string",
      "description": "Email of assigned user"
    },
    "priority": {
      "type": "string",
      "enum": ["low", "medium", "high"],
      "default": "medium",
      "description": "Task priority"
    },
    "due_date": {
      "type": "string",
      "format": "date",
      "description": "Due date"
    },
    "labels": {
      "type": "array",
      "items": { "type": "string" },
      "description": "Task labels/tags"
    }
  },
  "required": ["title"]
}
```

## מוסכמות מתן שמות

* **שם Entity**: השתמש ב-PascalCase עם תווים אלפאנומריים בלבד (למשל, `Task`, `TeamMember`, `ActivityLog`)
  * חייב להתאים לתבנית: `/^[a-zA-Z0-9]+$/`
  * תקף: `Task`, `TeamMember`, `Order123`
  * לא תקף: `Team_Member`, `Team-Member`, `Team Member`
* **שם קובץ**: השתמש ב-kebab-case תואם ל-entity (למשל, `task.jsonc`, `team-member.jsonc`, `activity-log.jsonc`)
* **שמות שדות**: השתמש ב-snake\_case (למשל, `board_id`, `user_email`, `due_date`)

## יחסים בין Entities

ליצירת יחסים בין entities, השתמש בשדות reference של ID:

```jsonc theme={null}
{
  "board_id": {
    "type": "string",
    "description": "Board this task belongs to"
  },
  "team_id": {
    "type": "string",
    "description": "Associated team ID"
  }
}
```

## Row Level Security (RLS)

Row Level Security (RLS) שולט אילו רשומות משתמשים יכולים לגשת אליהן בהתבסס על זהותם ומאפייניהם. כללי RLS מוגדרים לכל entity בתוך שדה ה-`rls` של הסכמה.

**חשוב:** אם לא מוגדר RLS, כל הרשומות נגישות לכל המשתמשים.

### פעולות RLS

RLS תומך בחמש פעולות:

| פעולה    | תיאור                                        |
| -------- | -------------------------------------------- |
| `create` | שלוט מי יכול להוסיף רשומות חדשות             |
| `read`   | שלוט מי יכול לצפות ברשומות                   |
| `update` | שלוט מי יכול לשנות רשומות                    |
| `delete` | שלוט מי יכול להסיר רשומות                    |
| `write`  | קיצור עבור `create`, `update` ו-`delete` יחד |

### ערכי הרשאה

כל פעולה מקבלת אחד מהערכים הבאים:

1. **`true`** - אפשר לכל המשתמשים (כולל אנונימיים/לא מאומתים)
2. **`false`** - חסום את כל המשתמשים
3. **אובייקט תנאי** - אפשר למשתמשים שתואמים לתנאי

### משתני תבנית

השתמש במשתני תבנית להפניה למאפייני המשתמש הנוכחי:

| תבנית                      | תיאור                                 |
| -------------------------- | ------------------------------------- |
| `{{user.id}}`              | ה-ID של המשתמש                        |
| `{{user.email}}`           | האימייל של המשתמש                     |
| `{{user.role}}`            | התפקיד של המשתמש                      |
| `{{user.data.field_name}}` | שדה מותאם מאובייקט ה-`data` של המשתמש |

### מאפייני Entity מובנים

לכל רשומת entity יש את המאפיינים המובנים האלה זמינים לכללי RLS:

| מאפיין         | תיאור                             |
| -------------- | --------------------------------- |
| `id`           | מזהה רשומה ייחודי                 |
| `created_date` | חותמת זמן כשהרשומה נוצרה          |
| `updated_date` | חותמת זמן כשהרשומה עודכנה לאחרונה |
| `created_by`   | האימייל של המשתמש שיצר את הרשומה  |

### סוגי כללים

יש שני סוגי תנאים שניתן להשתמש בהם:

**1. השוואת entity-to-user** - השווה שדות רשומה לערכי המשתמש הנוכחי:

```jsonc theme={null}
{
  "created_by": "{{user.email}}"
}
```

**2. בדיקת תנאי משתמש** - בדוק מאפייני משתמש ישירות באמצעות `user_condition`:

```jsonc theme={null}
{
  "user_condition": { "role": "admin" }
}
```

**הערות חשובות:**

* `user_condition` תומך רק ב**equality פשוט** (למשל, `{ "role": "admin" }`)
* **סינון שדה entity דורש קידומת `data.`:** השתמש ב-`{ "data.fieldname": value }` לסינון לפי ערכי שדה entity
* להשוואות שדות `data.*`, ניתן להשתמש באופרטורים: `$in`, `$nin`, `$ne`, `$all`
* אופרטורים לוגיים `$or`, `$and`, `$nor` זמינים לשילוב תנאים

⚠️ **לתבניות RLS מתקדמות ודוגמאות, ראה [rls-examples.md](https://docs.base44.com/developers/skills/base44-cli/references/rls-examples.md)**

### דוגמאות RLS

**גישה לבעלים בלבד:**

```jsonc theme={null}
{
  "created_by": "{{user.email}}"
}
```

**גישה מבוססת מחלקה:**

```jsonc theme={null}
{
  "data.department": "{{user.data.department}}"
}
```

**גישה למנהלים בלבד:**

```jsonc theme={null}
{
  "user_condition": { "role": "admin" }
}
```

**תצורת RLS מלאה:**

```jsonc theme={null}
{
  "name": "Task",
  "type": "object",
  "properties": {
    "title": {
      "type": "string",
      "description": "Task title"
    },
    "status": {
      "type": "string",
      "enum": ["todo", "in_progress", "done"],
      "default": "todo"
    }
  },
  "required": ["title"],
  "rls": {
    "create": true,
    "read": { "created_by": "{{user.email}}" },
    "update": { "created_by": "{{user.email}}" },
    "delete": { "created_by": "{{user.email}}" }
  }
}
```

### תבניות RLS נפוצות

**יצירה ציבורית, ניהול מנהלים בלבד (למשל, טפסי צור קשר, waitlists):**

```jsonc theme={null}
{
  "rls": {
    "create": true,
    "read": { "user_condition": { "role": "admin" } },
    "update": { "user_condition": { "role": "admin" } },
    "delete": { "user_condition": { "role": "admin" } }
  }
}
```

**גישה לבעלים בלבד:**

```jsonc theme={null}
{
  "rls": {
    "create": true,
    "read": { "created_by": "{{user.email}}" },
    "update": { "created_by": "{{user.email}}" },
    "delete": { "created_by": "{{user.email}}" }
  }
}
```

**משתמשים מחוברים בלבד:**

```jsonc theme={null}
{
  "rls": {
    "create": { "user_condition": { "id": "{{user.id}}" } },
    "read": true,
    "update": { "created_by": "{{user.email}}" },
    "delete": { "created_by": "{{user.email}}" }
  }
}
```

### מגבלות

* **user\_condition הוא equality בלבד:** `user_condition` תומך רק בהתאמה מדויקת (למשל, `{ "role": "admin" }`) - ללא אופרטורים
* **אין אופרטורי השוואה על user\_condition:** `$gt`, `$lt`, `$regex`, `$expr`, `$where` אינם נתמכים לתנאי משתמש
* **אין תבניות מקוננות עמוקות:** תבניות כמו `{{user.data.profile.department}}` עשויות שלא לעבוד

**אופרטורים נתמכים:**

* **אופרטורים לוגיים:** `$or`, `$and`, `$nor` לשילוב מספר תנאים
* **אופרטורי שדה (עבור שדות `data.*` בלבד):** `$in`, `$nin`, `$ne`, `$all`
* **סינון שדה entity:** השתמש בקידומת `data.` לסינון לפי ערכי שדה entity (למשל, `{ "data.status": "published" }` או `{ "data.completed": true }`)

⚠️ **ראה [rls-examples.md](https://docs.base44.com/developers/skills/base44-cli/references/rls-examples.md) לתבניות RLS ודוגמאות מקיפות**

### תבניות גישה מורכבות

לתבניות גישה מורכבות שדורשות תנאים מרובים (למשל, "owner OR admin"), יש לך שתי אפשרויות:

1. **השתמש בממשק המשתמש של Base44 Dashboard** - הלוח מאפשר הוספת מספר כללים לכל פעולה עם לוגיקת OR
2. **השתמש ב-entities נפרדים** - חלק נתונים למספר entities עם כללי גישה שונים
3. **השתמש בפונקציות backend** - יישם לוגיקת גישה מותאמת בפונקציות backend

## Field Level Security (FLS)

Field Level Security מאפשר לך לשלוט בגישה לשדות בודדים בתוך entity. כללי FLS מוגדרים בתוך הסכמה של כל שדה באמצעות מאפיין `rls`.

### פעולות FLS

FLS תומך באותן פעולות כמו RLS ברמת entity:

| פעולה    | תיאור                                        |
| -------- | -------------------------------------------- |
| `create` | שלוט מי יכול להגדיר שדה זה בעת יצירת רשומות  |
| `read`   | שלוט מי יכול לצפות בשדה זה                   |
| `update` | שלוט מי יכול לשנות שדה זה                    |
| `delete` | שלוט מי יכול לנקות שדה זה                    |
| `write`  | קיצור עבור `create`, `update` ו-`delete` יחד |

### דוגמת FLS

```jsonc theme={null}
{
  "name": "Employee",
  "type": "object",
  "properties": {
    "name": {
      "type": "string",
      "description": "Employee name"
    },
    "salary": {
      "type": "number",
      "description": "Employee salary",
      "rls": {
        "read": { "user_condition": { "role": "hr" } },
        "update": { "user_condition": { "role": "hr" } }
      }
    },
    "department": {
      "type": "string",
      "description": "Department name"
    }
  },
  "required": ["name"]
}
```

בדוגמה זו, רק משתמשים עם תפקיד `hr` יכולים לקרוא או לעדכן את שדה ה-`salary`. כל המשתמשים עם גישה ל-entity יכולים לקרוא/לעדכן שדות אחרים.

### הערות FLS

* אם לא מוגדר RLS ברמת שדה, השדה יורש את כללי ה-RLS ברמת entity
* כללי FLS עוקבים אחר אותו פורמט תנאי כמו RLS ברמת entity
* השתמש ב-FLS לשדות רגישים כמו משכורת, SSN או הערות פנימיות

## דחיפת Entities

פקודת `entities push` תדחוף את כל ה-entities שקיימים בתיקיית `base44/entities`.

```bash theme={null}
npx base44 entities push
```

לפרטים נוספים על פקודת ה-push, ראה [entities-push.md](https://docs.base44.com/developers/skills/base44-cli/references/entities-push.md).

<Note>דף זה תורגם באמצעות בינה מלאכותית. למידע המדויק והעדכני ביותר, עיין ב[גרסה האנגלית](/). </Note>
