1

Can't find any documentation on relationships with Lithum models (using MongoDB). Could anyone point me to some info or show me an example?

hakre
  • 193,403
  • 52
  • 435
  • 836
Cobby
  • 5,273
  • 4
  • 28
  • 41

4 Answers4

2

Thought you might like a quick update.

Relationships are being worked into Lithium right now, I'm not sure exactly how complete they are but I believe they are operational in some form. Check out the x-relationships branch for details.

UPDATE: For anyone Google-ing and finding this answer they are now in the core and hosted on github.

rich97
  • 2,809
  • 2
  • 28
  • 34
2

The lithium relationship work has been released with 0.10. There's the beginnings of documentation in the manual, though that's not live on the lithium site yet.

michaeltwofish
  • 4,096
  • 3
  • 28
  • 32
0

For basic relationships I would use the Ids, but realistically if you need to do a lot of relationships between collections you either need to rethink how your data is set up, or just switch to a relational database.

Non-relational databases are a poor choice when you need to have relationships.

dragonmantank
  • 15,243
  • 20
  • 84
  • 92
  • What about when you have a BlgoPost and a User and you want to link the two? ...just something basic like that. – Cobby Nov 27 '10 at 00:49
  • (Warning: I don't deal with Non-relational DBs very often, so this might be sub-optimal). You could store each post under the user, so you'd have something like User.posts as an array of posts. You'd then have to build functions to search through all the User.posts arrays to find something like the last 5 posts, for example. The other option, like I said, was to have Post.userId = User._id. – dragonmantank Dec 02 '10 at 18:22
0

You can use Doctrine 2 or another ORM for using relationships in Lithium with a relational database, but since Lithium is very much Mongo/Couch DB slanted in its approach, the question you have is less about Lithium and more about the NoSql approach that it is encouraging.

BTW I think relationships are not yet officially supported in Lithium, but NoSql have their own methods for mostly not needing them - or not needing them as much by nesting data in JSON like syntax. But I think this is one feature that looks like it will be coming in 1.0, expect a blog post on it fairly soon.

Richard
  • 1,162
  • 1
  • 11
  • 19