You can also fake your own flattened attribute by writing "Apple.getPlum()" and "Plum.getApple()" yourself using the intermediate entity.
On Fri, Feb 18, 2011 at 5:18 AM, Robert Zeigler <robert.zeig...@roxanemy.com> wrote: > You can access the intermediate object if you choose not to flatten the > relationship. There's nothing to prevent a join table from being represented > as its own entity in cayenne. It can make your application a little more > complicated, but I've done it before when the join table carries additional > meaningful information, eg, information that somehow modulates the join (eg: > creating a createDate column on the join table for keeping track of exactly > when the association was created... stuff like that). > > Cheers, > > Robert > On Feb 18, 2011, at 2/184:10 AM , Christian Grobmeier wrote: > >>> What semantically is "isFresh" attribute? Is it a some business logic >>> attibute, or simple "autoset" variable, like timestamp etc.? >> >> No its business logic. In fact it defines the view-rights for the >> specific apples to the plums :-) >> >>> If former, you cannot live without ApplePlum ObjEntity. Is the problem >>> then in just setting its default value? Then you can simply set it at >>> database level. >> >> OK, I will try to change my mind on this one. I have hoped I could >> somehow access the intermediate object. >> >> THanks! >> >> Cheers >> Christian >> >> >>> If the default value is dynamic, like timestamp, you can try intercept >>> Cayenne's generating of queries: >>> http://cayenne.apache.org/doc30/custom-batchquerybuilder-factory.html >>> >>> 2011/2/18 Christian Grobmeier <grobme...@gmail.com>: >>>> Hello, >>>> >>>> I have the following scenario: >>>> >>>> Apple 1 -> n ApplePlum n : 1 Plum >>>> >>>> I want store an additional flag in ApplePlum (lets say isFresh = true/false >>>> >>>> How can I do this? I know I should not use flattened relations, but >>>> they are so nice, I would like to keep them. At least it would lead to >>>> the Method getApplePlum->getPlum which is not very neat. >>>> >>>> In order to do so I have thought I could create a custom method in my >>>> Apple class, which copies some code from the _Apple class. >>>> >>>> Like this: >>>> >>>> public void addToAppleAsFreshPlum(Plum value) { >>>> String relName = "ApplePlum"; >>>> if (value == null) { >>>> throw new NullPointerException("Attempt to add null target >>>> DataObject."); >>>> } >>>> >>>> willConnect(relName, value); >>>> Object holder = readProperty("ApplePlum"); >>>> >>>> // Now I would like to get the object created by the holder: >>>> ((ApplePlum)holder).setFresh(true); >>>> >>>> getObjectContext().propertyChanged(this, relName, null, value); >>>> >>>> if (holder instanceof Collection) { >>>> ((Collection<Object>) holder).add(value); >>>> } >>>> else if (holder instanceof Map) { >>>> ((Map<Object, Object>) holder).put(getMapKey(relName, >>>> value), value); >>>> } >>>> >>>> setReverseRelationship(relName, value); >>>> } >>>> >>>> Of course this does not work. I wonder if there is another option for >>>> me? Any ideas? >>>> >>>> Thanks in advance >>>> Christian >>>> >>> >>> >>> >>> -- >>> Andrey >>> >> >> >> >> -- >> http://www.grobmeier.de > >