[Nitro] Accessing a database column with two different names

George Moschovitis george.moschovitis at gmail.com
Thu Oct 26 11:14:01 EDT 2006


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
>


-- 
http://www.gmosx.com
http://www.nitroproject.org


More information about the Nitro-general mailing list