Thanks Yuri,
that was the right way.

I've tested your idea with irb and it looks very good:

<code>
irb(main):034:0> Profile.each do |pr|
irb(main):035:1* puts "#{pr.name} | #{pr.project.count}"
irb(main):036:1> if pr.project.count == 1
irb(main):037:2> pro = pr.project.first
irb(main):038:2> pr.project.delete(pro)
irb(main):039:2> pr.save
irb(main):040:2>
irb(main):041:2* end
irb(main):042:1> puts "#{pr.project.count}"
irb(main):043:1> end
TEST1_EQP | 1
0
TEST1_STEEL | 1
0
TEST2_EQP | 1
0
TEST2_STEEL | 1
0
TEST3_EQP | 0
0
</code>

Thanks a lot again.
My problem should be solved.

Best regards,
Andreas

On 21 Jun., 16:06, Yuri <[email protected]> wrote:
> I think one of the delete methods is what you're after, 
> seehttp://bit.ly/co4Mce
>
> e.g.,
>
> p = Project.first(:code => 'AAC')
> w = p.wuser.first(:login => 'mcpl')
>
> p.wuser.delete(w)
>
> Seems from the source code delete_if would be a shorter way to do it
> (the docs above are a tad ambiguous on _if's intended result,) but
> I've not used it myself.
>
> Good luck,
> Yuri
>
> On Jun 21, 6:15 am, wea_gruena <[email protected]> wrote:
>
> > Sorry for this newbie question ;-)
> > But I didn't found a good solution in the mailings.
>
> > My problem:
> > I can't remove existing associations / relations between classes.
>
> > <code>
> > class Project
> >         #~ #PDMS projects
> >         include DataMapper::Resource
> >         property :code, String, :key => true, :length => 3, :required => 
> > true
> >         #...
> >         has n, :wuser, :through => Resource
> > end
>
> > class Wuser
> >         #~ #Windows user (login name)
> >         include DataMapper::Resource
> >         property :login, String, :key => true, :required => true
> >         #...
> >         has n, :project, :through => Resource
> > end
> > </code>
>
> > If I try to delete a relationship with:
>
> > <code>
> > p = Project.first(:code => 'AAC')
> > p.wuser.first(:login => 'mcpl').destroy
> > </code>
>
> > My ressource (Wuser 'mcpl') will be deleted.
>
> > Where is my mistake or how can I delete one association ?
>
> > Thanks before for your answers and help !!!

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