Friday, June 6, 2008

DataMapper: Parent / Child Relationship

I couldn't find an example at datamapper.org /docs for a parent child relationship.


After a little searching, I found the answer in the integration tests.  Here is the example:

class Node
include DataMapper::Resource

def self.default_repository_name
ADAPTER
end

property :id, Integer, :serial => true
property :name, String

has n, :children, :class_name => 'Node', :child_key => [ :parent_id ]
belongs_to :parent, :class_name => 'Node', :child_key => [ :parent_id ]

end

Hope that helps someone else.

36 comments:

  1. It looks more like a tree relationship then a parent/child relationship.

    ReplyDelete
  2. "In a hierarchical data model, data is organized into a tree-like structure. The structure allows repeating information using parent/child relationships: each parent can have many children but each child only has one parent."

    http://en.wikipedia.org/wiki/Hierarchical_model

    ReplyDelete
  3. This is very helpful, though I'm not too familiar with datamapper. I'm trying to see if it'll fit what I need.

    Could this be expanded to the parent becomes,
    has n, :children, :class_name => 'Node', :child_key => [:child_id]
    has n, :parents, :class_name => 'Node', :child_key => [:parent_id ]

    Something like that would work with activerecord, but, like I said I'm not too familiar.

    Cheers

    ReplyDelete
  4. scott,

    Actually I believe the syntax you suggested is what I first tried, and did not work, and caused the searching.

    DataMapper is still somewhat young, so check the integration tests referenced in the post for the most recent developments.

    ReplyDelete
  5. Ah, I figured it out.

    I didn't write a spec for it, nor would it stop any nonsensical inbred relationships, but:

    pastie.

    ReplyDelete
  6. Why not just use the dm-is-tree plugin?

    http://github.com/datamapper/dm-more/tree/master/dm-is-tree

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete
  8. We need lie detector tests for all government law enforcement officers at the city level, county level, state-level and federal level lie detector test

    ReplyDelete
  9. By being fully and completely who we are, we then attract relationships that reflect back to us the fullness of our creative being website.

    ReplyDelete
  10. they could have a perfectly happy marriage but want to add some spice or fun. After all, something doesn't need to be broken for it to get better https://relationadvisor.com/

    ReplyDelete
  11. It’s very excellent information and more real facts to provided that post.Thank you for sharing this information. 2018 hostgator coupons

    ReplyDelete
  12. This comment has been removed by the author.

    ReplyDelete
  13. We Provide Our Customers With Latest and up-to-date Dumps Questions & Answers with 100% Exam Passing Guarantee. We Promise Exceptional Success in First Attempt. PSE-Endpoint exam dumps

    ReplyDelete
  14. Thank you so much as you have been willing to share information with us. We will forever admire all you have done here because you have made my work as easy as ABC. Learn More

    ReplyDelete
  15. I just want to let you know that I just check out your site and I find it very interesting and informative.. Here

    ReplyDelete
  16. Consistently I go to my office I get myself vis-à-vis with a parent. 90% of the time it will be a mother. She will disclose to me in extraordinary detail what she considers (surmises) isn't right with her kid.Diono Radian RXT Car Seat Review

    ReplyDelete
  17. Hi,Thanks for the information about this Really nice Post.
    funny internet names:-
    https://www.coolwifinames.xyz/2018/11/funny-internet-names.html

    ReplyDelete
  18. So it will be troublesome attempting to specify all the relationship issues and what causes them.his secret obsession reviews

    ReplyDelete
  19. You must take action today to find your soul mate. You can meet your future Arab bride on the Internet for free.http://seksitreffit.cam

    ReplyDelete
  20. I really impressed after read this because of some quality work and informative thoughts . I just wanna say thanks for the writer and wish you all the best for coming!. como conquistar um homem

    ReplyDelete
  21. I Have Read Your Article its Amazing Thanks For Sharing Your Knowledge..
    Best Bow Sight

    ReplyDelete
  22. Presently please recall this was a child who felt comfortable around the lanes, she was no blessed messenger of blamelessness. For as long as two years she had split away, put dread into her parents and strolled the avenues.If you don’t want your child to be bullied

    ReplyDelete
  23. Have you heard of the saying that says that "what goes for the duck is also good for the geese" meaning that somebody somewhere is also having a serious challenge in his or her own relationship.Relationship Advice

    ReplyDelete
  24. This particular is usually apparently essential and moreover outstanding truth along with for sure fair-minded and moreover admittedly useful My business is looking to find in advance designed for this specific useful stuffs… Causas de la depresion

    ReplyDelete
  25. Spats are important just in light of the fact that all out outsiders turned sweethearts must change their desires.http://www.threesomesites.org/couples-seeking-men-top-5-threesome-dating-sites.html

    ReplyDelete
  26. Our endeavors to do this typically drives us rapidly to look at our own issues about limits, since taking on someone else's obligations brings us outside of where we want to be. adult friend finder

    ReplyDelete
  27. It was wondering if I could use this write-up on my other website, I will link it back to your website though.Great Thanks. infant

    ReplyDelete
  28. You must learn how to accommodate his or her weaknesses, some men are very fond of pointing out other persons mistakes rather than their strength, this will only generate strife and compound your relationship problem. 유흥알바

    ReplyDelete
  29. The feeling of being replaced or being betrayed is not easy to cope with and so the betrayed spouse or partner often walk out of the relationship. Sex Swings and Slings

    ReplyDelete
  30. Not a single second went without leaving me in utter surprise.free transsexual dating sites

    ReplyDelete
  31. Awesome and interesting article. Great things you've always shared with us. Thanks. Just continue composing this kind of post. https://singlescenedating.com/recon/

    ReplyDelete
  32. This particular is usually apparently essential and moreover outstanding truth along with for sure fair-minded and moreover admittedly useful My business is looking to find in advance designed for this specific useful stuffs… preschool photographer

    ReplyDelete
  33. . The free join makes it more user-friendly and simple, but if you look forward to finding more Milfs for cuckold dating, having an option to pay $ 99.95 for 12 months which make your cuckold experience perfect and nice. sexting websites

    ReplyDelete
  34. There are many threesomes, meeting your friends who have the same interest.the 3somedatingonline.com is a private, happy, safe threesome dating website and you can enjoy a good times on the site. couple seeking unicorns

    ReplyDelete