/** * Binds a unidirectional one-to-many creating a psuedo back reference property in the process. * * @param property * @param mappings * @param collection */ protected void bindUnidirectionalOneToMany(org.grails.datastore.mapping.model.types.OneToMany property, Mappings mappings, Collection collection) { Value v = collection.getElement(); v.createForeignKey(); String entityName; if (v instanceof ManyToOne) { ManyToOne manyToOne = (ManyToOne) v; entityName = manyToOne.getReferencedEntityName(); } else { entityName = ((OneToMany) v).getReferencedEntityName(); } collection.setInverse(false); PersistentClass referenced = mappings.getClass(entityName); Backref prop = new Backref(); PersistentEntity owner = property.getOwner(); prop.setEntityName(owner.getName()); prop.setName(UNDERSCORE + addUnderscore(owner.getJavaClass().getSimpleName(), property.getName()) + "Backref"); prop.setUpdateable(false); prop.setInsertable(true); prop.setCollectionRole(collection.getRole()); prop.setValue(collection.getKey()); prop.setOptional(true); referenced.addProperty(prop); }
final OneToMany oneToMany = (OneToMany) prop; final Object propValue = entityAccess.getProperty(oneToMany.getName()); if (propValue instanceof Collection) { Collection associatedObjects = (Collection) propValue; Class associationType = associatedEntity.getJavaClass(); persistentCollection = getPersistentCollection(associatedObjects, associationType); entityAccess.setPropertyNoConversion(oneToMany.getName(), persistentCollection); persistentCollection.markDirty(); newCollection = true; toManyKeys.put(oneToMany, keys); if (newCollection ) { entityAccess.setProperty(oneToMany.getName(), associatedObjects);
final OneToMany oneToMany = (OneToMany) persistentProperty; final Object propValue = embeddedEntityAccess.getProperty(oneToMany.getName()); if (propValue instanceof Collection) { Collection associatedObjects = (Collection) propValue;