Given two models Blog and Category would it be right to assign a blog to a category that hasn't been created yet? Then when the save() method is called on the Blog the Category would be saved through the Blog by being inserted first. Then the Blogs foreign key would be set to the Categories primary key.
PHP Code:
$blog = new Blog();
$blog['title'] = 'The Blogs Title';
$blog['entry'] = 'entry for this blog...';
$blog['created'] = time();
$blog['category'] = new Category(array('name'=>'vehicles'));
$blog->save(); // category inserted then blog
The reason why I ask is because hypothetically in terms of a dependency the Category seems like it should exist before being assigned as a dependency to the Blog/Model which it would relate (shown below).
PHP Code:
$category = new Category();
$category['name'] = 'vehicles';
$category->save(); // inserted and assigned primary key
$blog = new Blog();
$blog['title'] = 'The Blogs Title';
$blog['entry'] = 'entry for this blog...';
$blog['created'] = time();
$blog['category'] = $category;
$blog->save();
One particular instance where this would be increasingly convenient is any one to one relationship.
PHP Code:
$profile = Profile(array('email'=>'blah@blah.com'));
$profile->user = new User(array('name'=>'oddz'));
$profile->save(); // user would be saved before profile
Bookmarks