[Nitro] Accessing a database column with two different names

Lars Olsson lasso at lassoweb.se
Thu Oct 26 14:36:06 EDT 2006


Thanks George (and everybody else)!

Maybe I'm stupid, but with your suggested model I still get some strange 
behaviour:

sqlite> .schema ogstoragefile
CREATE TABLE ogstoragefile (filename text, realname text, content_type 
text, owner_oid integer, oid integer PRIMARY KEY);

Ok...

sqlite> .schema ogstorageuser
CREATE TABLE ogstorageuser (username text, password text, realname text, 
email text, storage_file_oid integer, oid integer PRIMARY KEY);

Now, please explain the function of the field 'storage_file_oid' in this 
table to me.

Sincerely

/lasso

________________________________________
Lars Olsson
lasso at lassoweb.nu
http://www.lassoweb.nu/

George Moschovitis skrev:
> This shold be like this:
> 
> 
> class StorageFile
>          attr_accessor :filename, String
>          attr_accessor :realname, String
>          attr_accessor :content_type, String
>          belongs_to :owner, StorageUser
>          has_many :viewers, StorageUser
> 
>          validate_unique :filename
> end
> 
> 
>  class StorageUser
>          attr_accessor :username, String
>          attr_accessor :password, String
>          attr_accessor :realname, String
>          attr_accessor :email, String
> 
>          has_many :files, StorageFile
>  end
> 
> then:
> 
> user = User['myusername']
> user_files = user.files
> 
> thats all ;-)
> 
> -g.
> 
> 
> PS: If you are using an older version of Og replace attr_accessor with
> property and User['name'] with User.find_by_name('name')
> 
> 
> 
> 
> 
> 
> On 10/25/06, Lars Olsson <lasso at lassoweb.se> wrote:
>> 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/
>> _______________________________________________
>> Nitro-general mailing list
>> Nitro-general at rubyforge.org
>> http://rubyforge.org/mailman/listinfo/nitro-general
>>
> 
> 

-- 
________________________________________
Lars Olsson
lasso at lassoweb.se
http://www.lassoweb.se/


More information about the Nitro-general mailing list