Re: ORM help
"Maksim Lin for technical support mailling lists" <[email protected]> Wed, 26 Mar 2008 16:33:18 +1100
| Newsgroups | gmane.comp.java.helma.general |
|---|---|
| Message-ID | <[email protected]> |
Hi Patrick, As far as I know collections with filters cannot be used to add objects to those collections. If you think about it, in your schema, Helmas ORM has no way of knowing that in order to associate a tag to a node, it has to add the tags id to the TAGS column of that node (I'm guessing its a comma seperated list?) I think its only working because the assoication is made "in memory" in helmas object cache and so disappears once you restart the app and if you look in the sql db table TAGS, there is no new entry in the TAGS column. To do many-to-many relations you'd normally use a "mapping" table in the sql db that has a column for each of the id's of the tables (node amd tag) that you are associating with each other. Theres a handy article about this on the helma site in: http://helma.org/docs/examples/subscriptions/ Having said that, actually I have in the past done exactly what your schema does but using "read-only" filtered collections and inserting objects id's "manually" into the relevant property (eg. your TAGS column in NODES table) where they are kept as a comma sperated list. However I found this to be a real pain and not really worth the trouble vs just creating a mapping table. Maks. > -----Original Message----- > From: [email protected] > [mailto:[email protected]] On Behalf Of Patrick Lee > Sent: Wednesday, 26 March 2008 12:36 > To: Helma User Mailing List > Subject: [Helma-user] ORM help > > Hi, > > I'm trying to get my head around the ORM in Helma. Best way > to explain is probably to show what I have. There's a > prototype called "Node" and one called "Tag" each Node can > have many tags associated to it and each tag can be > associated to many Nodes. > > Node/type.properties includes this: > > tag_ids = TAGS > tags = collection(Tag) > tags.accessname = TITLE_SHORT > tags.filter = TAG.ID IN (${NODE.TAGS}) > > Tag/type.properties includes this: > > nodes = collection(Node) > nodes.filter.additionalTables = TAG > nodes.filter = TAG.ID = ${ID} AND FIND_IN_SET(TAG.ID, NODE.TAGS) > > I also have all the tags on the root like so: > Root/type.properties: > tags = collection(Tag) > tags.accessname = TITLE_SHORT > > The problem I'm having is that whilst I seem to be able to > add a Tag to a Node (eg, this.tags.add(new Node())) and > access them via the URL, every time open the URL for a Node, > this.tags.list() is empty. > > Any clues? Have I got something wrong here? > _______________________________________________ > Helma-user mailing list > [email protected] > http://helma.org/mailman/listinfo/helma-user >