-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No docs about many-to-many relationships #45
Comments
The Omeka "classic" ORM is home-grown; the only framework it's built on is Zend_Db which is a very lightweight abstraction layer. All the "ORM" functionality is Omeka-specific. You are correct, you're not finding this in the documentation because it isn't there. More than not being documented, the feature simply doesn't exist. Omeka and its plugins turn out to use very few many-to-many relationships, so the Omeka_Record system doesn't have any facilities for dealing with database tables without an ID column. If you want to use the ORM for a table like this, you have to just accept the unnecessary IDs. Otherwise you can manage the rows "manually" and only have them interface with the ORM by being used in joins. The "default" Omeka Classic way to handle this situation would just be to accept the IDs. For many reasons including this one, Omeka S uses Doctrine as its ORM, which allows for fine-grained control over primary keys and also automatic handling of many-to-many relationships. A major focus of "classic" Omeka is backwards compatibility and so major changes to core components like these are unlikely. |
This is the kind of information I would expect to find in the docs. It would have saved me time. |
I read the documentation, and then started writing a plugin by looking at the source code from an existing plugin, and inspecting the source code of Omeka, because reading the documentation left me exactly at the same point where I was before reading it.
I needed to create a table representing a Many-to-Many relationship between two models. That means that the primary key is made of two fields, one referencing the id of a table represeting one model, and the other referencing the id of the table representing another model. In a standard mapping of an Entity-Relation model to a database structure, the table representing the many-to-many relation shouldn't have a useless, redundant, auto-increment 'id' field, it just has the primary key built with the ids referencing the two model tables.
There's NOTHING about this in the documentation, so I tried.
This is the statement creating the table in the installation hook:
This is a many-to-many relationship between
Collection
andCollection
. What it means and what it's for are not relevant here.I created a model
AdditionalParentCollection
and a tableTable_AdditionalParentCollection
.I find NOTHING in the documenation about how I'm supposed to tell Omeka that this table represents a relation and not a model, and/or that the primary key is not
id
, let alone that it's made of two fields. So I thought I'd try by just never usingfind()
(onlyfindBy()
) and never mentioning the id and see what would happen.In my
hookAfterSaveCollection
I have this:This looks like it shouldn't cause any problem by itself. I'm creating a new instance of the model, populating the only two fields that it has, and trying to save it.
This causes this error:
which, as per another annoying bug I reported a few minutes ago, doesn't even show me the full query that causes the error.
I wouldn't necessarily expect this to work as is. I would expect to be able to find, in the documentation, an explanation of how I am supposed to do this.
And I believe I know how to look. I don't think I'm not finding it in the documentation because I don't know where to look or because it's obvious enough. I'm not finding it because it's not there.
Nor is there a link to a place where to look (e.g., if Omeka is built on top of some other well-known framework, a link to its documentation or a mention of its name)
The text was updated successfully, but these errors were encountered: