Re: Unable to fetch
Sebastien Bigaret <[email protected]> 23 May 2005 15:59:55 +0200
| Newsgroups | gmane.comp.python.modeling |
|---|---|
| Message-ID | <[email protected]> |
Hi James,
James Laska <[email protected]> wrote:
> Sorry to respond to my own post.
>=20
> It appears this error was triggered by an incorrect specification of
> the 'name' attribute of the <entity>.
>=20
> Failed with:
> <entity name=3D'prefix_project' externalName=3D'prefix_project'
> className=3D'Project'>
>=20
> Works with:
> <entity name=3D'Project' externalName=3D'prefix_project' className=3D'P=
roject'>
>=20
Just a note even if you already solved your problem, to help making
things clearer in case they need to.
There is a priori no reason for className, externalName and entity's
name to be the same. Class name is, well, the class name ;) the
external name is the name of the corresponding table in the database,
and the entity's name is the identifier the framework uses for that kind
of object.
This explains the behaviour you previously got, because EC.fetch() and
EC.fetchCount() take an entity's name as their 1st parameter
http://modeling.sf.net/API/Modeling-API/public/Modeling.EditingContext.Edit=
ingContext-class.html#fetch
So if you want to keep 'prefix_project' as the entity's name, such as
in:
<entity name=3D'prefix_project' externalName=3D'prefix_project'
className=3D'Project'>
then you'll ask for that entity. So, as you noticed, this fails:
>>> ec.fetchCount('Project')
because there is no such entity named 'Project'; however, this succeeds:
>>> ec.fetchCount('prefix_project')
-- S=E9bastien.
> On 5/22/05, James Laska <[email protected]> wrote:
> > Greetings,
> >=20
> > I am new to the Modeling framework and have been reading the
> > UsersGuide and working through examples in the document and in tests/.
> > I am at the stage where I have defined a sample model (xml). I can
> > use that model to generate the python classes and the DB schema.
> >=20
> > $ find testmdl/ -type f -name "*py"
> > testmdl/setup.py
> > testmdl/MDL/__init__.py
> > testmdl/MDL/Project.py
> > testmdl/MDL/model_testmdl.py
> > testmdl/__init__.py
> > testmdl/Project.py
> >=20
> > I am also able to insert new values into my tables:
> >=20
> > >>> from Modeling.EditingContext import EditingContext
> > >>> from testmdl.Project import Project
> > >>> ec =3D EditingContext()
> > >>> p =3D Project()
> > >>> p.setTitle("Testing 1 2 3")
> > >>> ec.insert(p)
> > >>> ec.saveChanges()
> >=20
> > However, when it comes to ec.fetch() or ec.fetchCount() I continue to
> > get a traceback (regardless of whether or not I provide a qualifier):
> >=20
> > >>> ec.fetchCount('Project')
> > Traceback (most recent call last):
> > File "<stdin>", line 1, in ?
> > File "/usr/lib/python2.4/site-packages/Modeling/EditingContext.py",
> > line 1259, in fetchCount
> > fs=3DFetchSpecification(entityName, qualifier=3Dqualifier, deepFlag=
=3DisDeep)
> > File "/usr/lib/python2.4/site-packages/Modeling/FetchSpecification.py=
",
> > line 52, in __init__
> > raise ValueError, 'Unable to find a ClassDescription for
> > entityName: %s. Is the corresponding model loaded?'%entityName
> > ValueError: Unable to find a ClassDescription for entityName: Project.
> > Is the corresponding model loaded?
> >=20
> > I can see that my previous insert(s) were properly INSERTed in to the t=
able:
> >=20
> > > select proj_id, proj_title from project;
> >=20
> > proj_id | proj_title
> > ---------+---------------
> > 1 | First
> > 2 | Testing 1 2 3
> >=20
> > Any thoughts on what I might be missing? I searched the list archives
> > (and google) for the same ValueError but have turned up empty. I have
> > also been poking through FetchSpecification+classDescriptionForName
> > but have turned up nothing so far. I have installed out of a cvs
> > checkout as of last week (2005-05-17).
> >=20
> > Any help or guidance would be appreciated.
-------------------------------------------------------
This SF.Net email is sponsored by Oracle Space Sweepstakes
Want to be the first software developer in space?
Enter now for the Oracle Space Sweepstakes!
http://ads.osdn.com/?ad_id=7412&alloc_id=16344&op=click