DEV Community

Kevin Expósito
Kevin Expósito

Posted on • Originally published at positionsticky.com on

Emberjs Data Model Migration Guide

This guide covers migrating Ember Data models from the legacy syntax to the modern one.

Useful docs:

Table of Contents

  1. Overview
  2. Basic Migration Pattern
  3. Attributes Migration
  4. Relationships Migration
  5. Computed Properties Migration
  6. Testing Migrated Models
  7. Complete Example
  8. Best Practices

Overview

The migration involves converting from:

  • DS.Model.extend({...})export default class ModelName extends Model
  • attr()@attr() decorator
  • belongsTo()@belongsTo() decorator
  • hasMany()@hasMany() decorator

Basic Migration Pattern

Before (Legacy Syntax)

After (Modern Syntax)


Attributes Migration

Simple Attributes

Attributes with Default Values


Relationships Migration

BelongsTo Relationships

HasMany Relationships


Computed Properties Migration


Testing Migrated Models

Basic Test Setup

Testing Attributes

Testing Computed Properties


Complete Example

Before (Legacy Model)

After (Modern Model)

Top comments (0)