posted by
fede
on Jan 4
GORM (Groovy)
------------
class Book {
static belongsTo = Author
static hasMany = [authors:Author]
static constraints = {
title(maxSize:200)
}
String title
}
class Author {
static hasMany = [books:Book]
String name
}
01 - Example:
def book = Book.findByTitle('Groovy in Action')
book.addToAuthors(name: 'Dierk Koenig')
book.save()
02 - Example:
def book = new Book(title: 'Misery')
author.addToBooks(book)
author.save()
GORM (PHP)
------------
class Book {
static public $belongsTo = 'Author';
static public $hasMany = array('authors' => 'Author');
static public $constraints = array('title' => array('maxSize' => 200));
static public $dataTypes = array('title' => 'string');
public $title;
}
class Author {
static public $hasMany = array('books' => 'Book');
static public $dataTypes = array('name' => 'string');
public $name;
}
01 - Example:
$book = Orm::new('Book')->findByTitle('ZF in Action');
$book->addToAuthors(array('name'=>'Dierk Koenig');
$book->save();
02 - Example:
$book = Orm::new('Book', array('title'=>'Misery'));
$author->addToBooks($book);
$author->save();
reply
posted by
fede
on Jan 26
Repositories are not part of the Service Layer, they are part of the Domain Layer. The Repository provides a higher level of data manipulation, and acts as a link between the Domain and Persistence Layers (Entity <- Repository -> DAO). The Repository pattern is a very common pattern and most ORMs use it.
Service classes are not part of the Domain or Persistence Layers and therefore do not provide methods to access data, such as dynamic finders. Dynamic finders are usually found in the Repository.
Some people think that ORM is a pattern, but it’s not. Mapping relationships is just a technique that uses different patterns to solve the problem of converting data between incompatible systems, e.g. DataMapper, DAO, Factory, Repository, Service Locator, etc.
reply