On 14 Oct 2009, at 19:50, Chris wrote:
> 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/
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"DataMapper" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/datamapper?hl=en
-~----------~----~----~----~------~----~------~--~---