On Nov 23, 9:39 am, "Dan Kubb (dkubb)" <[EMAIL PROTECTED]> wrote:
> Hi Mark,
>
> > Although my Ruby knowledge is fairly rudimentary I've been attempting
> > to read some of the DataMapper code since I was curious about the
> > issue regarding associations that I raised in an earlier post. I think
> > I'm slowly getting an understanding of how some things work, but there
> > are a couple of areas I'm struggling to understand. I'd really
> > appreciate some pointers from any of the experts here...
>
> Keep in mind that we're currently rewriting most of the associations
> code for the spec/doc rewrite happening in github.com/dkubb/dm-core.
> We're speccing the behavior as it is supposed to be, marking any specs
> that fail as pending, and then working on making the specs pass once
> we finish speccing a class or method.
>
> Some of the associations code like Many to Many is likely to be 100%
> rewritten because it doesn't even pass 50% of the specs we have for
> it.
> While One to Many will probably become much simplified as a subclass
> of Collection. We've already succeeded in eliminating the Many To One
> Proxy object altogether.
Thanks for the heads-up Dan. Do you have any rough time frame in mind
for the rewrite?
> > klass = ManyToMany if options[:through] == DataMapper::Resource
>
> > I'm not sure how to interpret the semantics of 'options[:through] ==
> > DataMapper::Resource' in the second line above. My first impression
> > was that 'DataMapper::Resource' represents a constant containing the
> > definition of the Resource module.
>
> In this case it's just a convention that shows the in-between join
> model is an anonymous Resource. You can also use :through
> => :association_name to specify a specific association to traverse.
Ok, I think I understand - I was forgetting you could declare :through
=> Resource, and assumed that the other case, :through
=> :association_name would use ManyToMany as well. But I see now that
it uses OneToMany.
> > Second question... The method 'setup' that is called on the ManyToMany
> > object 'klass' when the condition above succeeds is defined in
> > associations/manytomany.rb and adds new methods to model objects using
> > 'model.class_eval...' (at least that's what I think is going on).
>
> That's correct. Each of the Associations libraries has a setup method
> that creates the correct accessor and mutator within the resource when
> has() or belongs_to() is used.
>
> > One of those methods, '#{name}_association', instantiates a new Proxy
> > object with 'association = Proxy.new(relationship, self)'. The Proxy
> > class is defined in the module as a subclass of
> > DataMapper::Associations::OneToMany::Proxy, which is where the 'new'
> > method is defined (in associations/onetomany.rb). 'new' includes a
> > call to 'super(attributes)'.
>
> > My question is what does 'super' refer to here? I understand it to be
> > a call to the method 'new' on Proxy's parent class. Yet Proxy is not
> > explicitly defined here as a subclass. I would take it to be a
> > subclass of Object, but Object.new(attributes) doesn't seem to fit in
> > this context.
>
> This is a proxy class so all unhandled methods are delegated to
> #method_missing and propagated to the underlying Collection. In the
> case of Ruby, when you call super(), it will use #method_missing (if
> it exists) rather than directly going up the chain to the same-named
> method in the parent class.
Ah, didn't think of that. Thanks,
Mark.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---