Create Model relationship with just an ID rather than full Model? Is it possible to just assign the ID to the owning side of a relationship rather than querying the DB, loading the record and assigning it?

Something similar to Doctrines _getReference()


http://www.doctrine-project.org/api/orm/2.1/class-Doctrine.ORM.EntityManager.html#_getReference
https://stackoverflow.com/a/9308576/1982031
I think that's actually the way to do it, assign the id to the owning record:

$record = new Cocktails_CocktailRecord;
$record-&gt;authorId = 10;
$record-&gt;title = "Gin Tonic";
$record-&gt;save();


When getting the record from the db, the record is turned into a model, at this point, records and models are only dealing with authorId, not the whole record. Your model will then have to define a getAuthor() method that will get the author user for you:

public function getAuthor()
{
    if ($this-&gt;authorId) {
        return craft()-&gt;users-&gt;getUserById($this-&gt;authorId);
    }
}


This way your model only loads the relationship when you actually use it:

$model-&gt;getAuthor();