Re: Many to Many Relations
2005-01-03 07:05:01 GMT
Hi Martin,
Martin_Snyder wrote:
>
> Has anyone used SimpleORM in a system that requires many to many
> relationships? I'm attempting this currently and running into some
> issues.
>
> Normally I would do this with a simple mapping table containing
> foreign key references to the two object types.
>
> SimpleORM however won't allow me to create a table without a primary
> key, so the obvious alternative appears to be to make every column
> part of the primary key.
>
> When I did that however, simpleORM doesn't handle rows in a table like
> that particularly well. I can create new records by calling
> findOrCreate with an object array with the primary key values. At
> that point though, no matter what I do the record is never actually
> saved in the database. Perhaps this is because it's not considered
> dirty because no non-key fields have been modified. Of course,
> SimpleORM prevents me from updating a primary key field to mark it as
> dirty.
Use the setDirty() method to mark the object as dirty:
SConnection.begin();
Link link = (Link) Link.meta.findOrCreate(new Object[] {objA, objB});
link.setDirty();
(Continue reading)
RSS Feed