UnionOfRAD/lithium — Issue #237: RFC: CouchDB DataSource adapter has no default way of discriminating subclasses of Model yet?
Author: Tomen
Created: 2012-01-03 08:37:19+00:00
State: open

Yesterday i tried to change my data source from MongoDB to CouchDB. The first issue that came up was at first strange.

Say you have the following code:

Companies::create()->save();
Employees::create()->save();
$allCompanies = Companies::all();

This would give you the Companies-object and the Employees-object, in fact all documents in the database. I was really puzzled by this. On IRC, @gwoo then informed me, that the way that lithium intends me to use the CouchDB data source is to provide designs/views. Looking again at how CouchDB works, this makes good sense.

First question: Is this somewhere mentioned in the documentation? I spent quite some time with it but cannot remember reading this. Maybe i just skipped over it because i thought "this is not for me, i use mongo" at the time? Or is this piece missing?

Now what my problem with this is, is: Lithium is always very helpful to me by providing a default solution for my problem. In this case, it does not. And i don't think everyone is lucky enough to get @gwoo at the right time to provide the right answer =)

If i am right up until to this point, there are a few solutions that come to my mind, that would solve this little problem:

1) "Brute force" - Every time you query documents of a specific class, lithium checks if there is a view for that and if not, it creates one ad hoc.

1a) A filter that does the same.

2) A console command, that creates views for all your model classes.

3) One of the above, in a plugin

Am i right with my thoughts so far? Did i miss something? What do you think?