Seems odd that the above code snippet is not handled on creation of
the relationships, no? Explicitly defining the property is an option,
yes, but as you say "redundant". I suppose for now, I'll add an
initializer (Rails) to handle that loading.

On Aug 10, 9:09 am, Martin Gamsjaeger <[email protected]> wrote:
> Thanatos,
>
> If I'm not mistaken merb_datamapper uses the following snippet to
> prevent this kind of error:
>
>       DataMapper::Model.descendants.each do |model|
>         model.relationships.each_value { |r| r.child_key }
>       end
>
> An alternative is to define all your FK properties explicitly and not
> rely on the relationship methods to create them for you. However, it's
> generally considered to be kind of redundant to do so, and I think
> there are plans to let datamapper automatically handle this situation
> itself, so that the above trick is not needed.
>
> Hope this helps
> snusnu
>
>
>
> On Mon, Aug 10, 2009 at 06:10, Thanatos<[email protected]> wrote:
>
> > I have a belongs to relationship, the reader/writer is created on
> > declaration, however, the property is not created at the same time.
> > So, when I call #first, a property does not exist for me to use. So,
> > when I have an edit form with a drop-down to assign to
> > relationship_id, I get an error unless I call the relationship.
>
> > Can the associated property be created (#child_key method) when the
> > reader/writer are created? Or is there another way I should be doing
> > my edit form? This also breaks any calls to #update which assign to
> > the property.
>
> > Note: if #new is called on the model, #assert_valid calls #child_key
> > to create the property.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to