Skip to content

Commit

Permalink
improve readme's Dynamic Properties docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Mulkave committed May 24, 2014
1 parent 67d2324 commit a15fbd1
Showing 1 changed file with 48 additions and 52 deletions.
100 changes: 48 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,6 @@ MERGE (account)<-[rel_user_account:ACCOUNT]-(user)
RETURN rel_user_account;
```

##### Dynamic Loading

```php
$phone = Phone::find(1006);
$user = $phone->user;
```

The Cypher performed by this statement will be as follows:

```sql
Expand All @@ -142,35 +135,6 @@ WHERE id(phone) = 1006
RETURN user;
```

##### Eager Loading

```php
class Book extends Eloquent {

public function author()
{
return $this->belongsTo('Author');
}
}
```

Loading authors with their books with the least performance overhead possible.

```php
foreach (Book::with('author')->get() as $book)
{
echo $book->author->name;
}
```

Only two Cypher queries will be run in the loop above:

```sql
MATCH (book:`Book`) RETURN *;

MATCH (book:`Book`), (book)<-[:WROTE]-(author:`Author`) WHERE id(book) IN [1, 2, 3, 4, 5, ...] RETURN book, author;
```

### One-To-Many

```php
Expand Down Expand Up @@ -216,21 +180,6 @@ class Post extends NeoEloquent {
This represents an `INCOMING` relationship direction from
the `:User` node to this `:Post` node.

##### Dynamic Loading

```php
$post = Post::find(1011);
$autor = $post->author;
```

The Cypher performed by this statement will be as follows:

```sql
MATCH (post:`Post`), (post)<-[rel_post_author:POSTED]-(author:`User`)
WHERE id(post) = 1011
RETURN author;
```

### Manty-To-Many

```php
Expand Down Expand Up @@ -262,7 +211,7 @@ The Cypher performed by this statement will be as follows:
```sql
MATCH (user:`User`), (followers:`User`)
WHERE id(user) = 1012 AND id(followers) = 1013
CREATE (user)-[rel_user_followers:FOLLOWS]->(followers)
CREATE (user)-[:FOLLOWS]->(followers)
RETURN rel_follows;
```

Expand Down Expand Up @@ -295,6 +244,53 @@ WHERE id(user) = 1012
RETURN rel_follows;
```

### Dynamic Properties

```php
class Phone extends Eloquent {

public function user()
{
return $this->belongsTo('User');
}

}

$phone = Phone::find(1006);
$user = $phone->user;
// or getting an attribute out of the related model
$name = $phone->user->name;
```

### Eager Loading

```php
class Book extends Eloquent {

public function author()
{
return $this->belongsTo('Author');
}
}
```

Loading authors with their books with the least performance overhead possible.

```php
foreach (Book::with('author')->get() as $book)
{
echo $book->author->name;
}
```

Only two Cypher queries will be run in the loop above:

```sql
MATCH (book:`Book`) RETURN *;

MATCH (book:`Book`), (book)<-[:WROTE]-(author:`Author`) WHERE id(book) IN [1, 2, 3, 4, 5, ...] RETURN book, author;
```

## Edges

### Introduction
Expand Down

0 comments on commit a15fbd1

Please sign in to comment.