nested models when id is unavailable

I have a controller that's creating model objects from XML input. Something like:

<status-report>   <completed type="boolean">true</completed>   <person>     <name>Scott</name>   </person> </status-report>

I have two models, StatusReport and Person.

I want to create a new Person iff there is not already one with that name. Then, link that Person to this StatusReport.

The built-in accept_nested_attributes_for doesn't work for me since it will always create a new Person unless I provide an id to an existing one.

I have full control over the XML input. What I don't have is a good way for it to include the id of an existing Person.

Right now I have a fat controller explicitly looking for a Person, then doing Person.create! if needed. I'm sure there's a better way.

Just in case anybody cares about the resolution of this, I'll answer my own post.

In my StatusReport model, I added:

def person_attributes(params = {})   self.person = Person.find_or_initialize_by_name(params[:name]) end

Then I changed the XML to: <status-report>   <completed type="boolean">true</completed>   <person-attributes>     <name>Scott</name>   </person-attributes> </status-report>

This works much like accepts_nested_attributes_for.