[Nitro] Accessing a database column with two different names
Lars Olsson
lasso at lassoweb.se
Wed Oct 25 13:55:04 EDT 2006
Hi list!
Consider the following simple db schema:
class StorageFile
property :filename, String
property :realname, String
property :content_type, String
has_one :owner, StorageUser
has_many :viewers, StorageUser
validate_unique :filename
end
class StorageUser
property :username, String
property :password, String
property :realname, String
property :email, String
end
When I tried finding all files belonging to I got an error:
@myfiles = StorageFile.find do |file|
file.owner == some_storageuser.oid
end
as the column 'owner' doesn't exist.
I then checked SQLite for the table definition:
sqlite> .schema ogstoragefile
CREATE TABLE ogstoragefile (filename text, owner_oid integer, oid
integer PRIMARY KEY, content_type text, realname text);
which claims I should be accessing the owner with the 'owner_oid' name.
I find this quite unintuitive. If I use 'owner' when I create an object
I expect to be able to reuse that name when extracting information from
the very same object. Is this a bug or by design?
Sincerely
/lasso
--
________________________________________
Lars Olsson
lasso at lassoweb.se
http://www.lassoweb.se/
More information about the Nitro-general
mailing list