Q:

How to allow a related model in Yii to be empty

In my Yii application I have a pretty simple model setup. I've used the gii autogenerated code to create the basic CRUD, while I get the data for my app in place.
So, I have Authors, and Books. A Book belongs_to an Author.
I have a huge list of books already to enter - but as I haven't entered the Authors yet - none of my books will save, as I keep getting "Trying to get property of non-object" when I save without selecting an author- despite not making Author "required".
As I haven't got my list of books organised by author (it's a straight list of titles in a CSV list) this is preventing me saving any Books.
How can I make the Author optional?

A:

So the answer was more simple than I realised - I had the wrong relationship. Instead of a "belongs to" I needed a "has one". The has one relationship allows for nulls.

