On 28/03/2010 16:51, Peteris Krumins wrote:
Hi all,

I can't wrap my mind around a problem of naming mapped classes. Here
is an example to explain what is going on.

Suppose I have a table in the database called "comments". Now I have
two choices how to call the class that will represent "comments".
Either "class Comments" in plural, or "class Comment" in singular.

If I name the class in plural, "class Comments", then a query like:

     Session.add(Comments("a new comment"))

sounds weird. I am adding a new comment but using plural to refer to
it "I am adding a new Comments". Which is just weird.

The other possibility is to use singular, "class Comment". That fixes
the above problem but introduces a new problem, particularly,

     Session.query(Comment).all()

But now I am querying singular expression "get all comment" to get
plural out. My mind refuses to understand that.

Anyone else has the same issues on naming things?

I am thinking the workaround is to introduce aliases, "Comment" and
"Comments" and use them where necessary:

     Session.add(Comment("a new comment"))

and

     Session.query(Comments).all()


where both Comment and Comments refer to the same table.
To me that would be even more confusing:)

I use declarative and based my namings on what Michael suggests/shows in the documentation. At the time wasn't really thinking to much about it, did it as it made following samples and comparing it to my code easier.

Maybe this helps:

aComment = Session.add(Comment("a new comment"))

and

allComments = Session.query(Comment).all()

The class is always "only" one instance of whatever, the table contains many of them and 
"only" the query result is the equivalent of that if you use "all()" - no?

Werner



--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to