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.

>       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.

> 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.

However, like I said above this won't be the case in the near future
as we're updating DataMapper::Associations::OneToMany::Proxy so that
it inherits from Collection. This will probably cut out at least 80%
of the duplicate code between the two.  At the same time it will no
longer be a Proxy, so we'll probably drop the "Proxy" designation and
they'll become DataMapper::Associations::OneToMany objects.

Dan
(dkubb)
--~--~---------~--~----~------------~-------~--~----~
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