> property :world_region_id, Integer, :default => 1
This made me think, wouldn't-it-be-nice-if...
...you could declare the default of an association?
The reason I say this is that while defaulting a foreign key property
works if you save immediately, it doesn't let you build object graphs
in memory. I've been bitten by a bug I let creep in by setting
properties directly, that lurked for a while until we finally fixed it
by loading all the associated objects. (In general, I've found using
ids in the domain model dangerous.)
I'm thinking something like this:
belongs_to :job_role,
:default => lambda { |r, p| JobRole.first(:name =>
"Boss" ) }
I wrote a spec[1] not long ago to see if the behaviour existed - which
it doesn't - but I wasn't sure about putting it on Lighthouse.
WDYAT? Worth filing a ticket?
Ashley
[1] http://gist.github.com/213331
--
http://www.patchspace.co.uk/
http://www.linkedin.com/in/ashleymoran
http://aviewfromafar.net/
> I think this is good behavior. I've been slowly adding options that
> are available to the underlying property (like :nullable) to the
> belongs_to API when it makes sense, and I think the ability to declare
> a default parent resource like this fits with the overall API.
>
> If you want to create a ticket, tagged as "suggestion" I'll take a
> look at it when I cycle around and do another series of fixes/
> refactoring to the Relationship code.
Done:
Ashley