Yeah, nah, that doesn't fly...
ArgumentError: +options[:order]+ entry
"owner_shared_resource.ordinal" does not map to a property in
SharedResource
Thanks for the reply at any rate.
It seems to me that dm has long forgotten the information on
OwnerSharedResource by the time it constructs the shared_resources
list... is there no way I can be more specific about the join when
defining my shared_resources association? I guess I need to define a
property that is only valid when joining... It makes me want to
revisit my modelling, but it seems like a reasonable thing to do:
+---------+ * * +----------------+
| Owner |------+------| SharedResource |
+---------+ : +----------------+
:
:
+----------+----------+
| OwnerSharedResource |
+---------------------+
| ordinal |
+---------------------+
Another solution would be to work with instances of
OwnerSharedResource and let them delegate to SharedResource (in
rails):
class OwnerSharedResource
...
belongs_to :owner, :key => true
belongs_to :shared_resource, :key => true
property :ordinal, Integer
delegate :prop, :prop=, :to => :shared_resource
def initialize(attributes={},&block)
super(attributes,&block)
self.shared_resource = SharedResource.new if
self.shared_resource.nil?
end
end
class SharedResource
...
has n, :owners, :through => :owner_shared_resources
property :prop, ...
end
class Owner
...
has n, :owner_shared_resources, :order => [:ordinal]
end
On Aug 5, 5:07 am, Rip the Jacker <[email protected]> wrote:
> You may have to write it like:
>
> has n, :shared_resources, :through
> => :shared_resource_ordinals, :order =>
> ['owner_shared_resource.ordinal']
>
> I don't know if order clauses work through joins like that though, but
> give it a shot!
>
> On Aug 3, 10:18 pm, Corin <[email protected]> wrote:
>
>
>
>
>
>
>
> > Hi,
>
> > I'm working with a many-to-many relationship between objects (Owner)
> > that own a shared resource (SharedResource), where the relationship
> > has an attribute that indicates the ordering of shared resources for a
> > particular owner (ordinal). My problem is that I can't seem to get an
> > order list of shared resources on the owner side.
>
> > Here's my setup:
>
> > class Owner
> > ...
> > has n, :owner_shared_resources, :order => [:ordinal]
> > has n, :shared_resources, :through => :owner_shared_resources
> > end
>
> > class OwnerSharedResource
> > ...
> > belongs_to :owner, :key => true
> > belongs_to :shared_resource, :key => true
> > property :ordinal, Integer
> > end
>
> > class SharedResource
> > ...
> > has n, :owners, :through => :owner_shared_resources
> > end
>
> > Using `Owner.first.shared_resources` gives an unordered list. I have
> > tried this:
>
> > class Owner
> > ...
> > has n, :shared_resource_ordinals, OwnerSharedResource, :order =>
> > [:ordinal]
> > has n, :shared_resources, :through => :shared_resource_ordinals
> > end
>
> > But to no avail.
>
> > I have ended up with:
>
> > class Owner
> > ...
> > has n, :owner_shared_resources, :order => [:ordinal]
> > def shared_resources
> > self.owner_shared_resources.map {|x| x.shared_resource}
> > end
> > end
>
> > Which has obvious drawbacks.
>
> > What am I missing here?
--
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.