[PonyORM-list] Always prefetch some related entities ?

Gamesbrainiac gamesbrainiac at gmail.com
Sat Dec 13 07:04:08 UTC 2014


Change the optional attribute `lazy` to False. So, for example:

class File(database.Entity):
    filename = Required(unicode, lazy=False)
    ...

And then try. Admittedly, I have not tried this out myself, but this should
work.

On Sat, Dec 13, 2014 at 12:50 PM, Tomislav Tustonic <ttustonic at outlook.com>
wrote:
>
> Hello
>
> Is it possible to make an entity always prefetch some related entities?
> For example, something like this:
>
> class Directory(database.Entity):
>     path = Required(unicode, unique=True)
>     files = Set(lambda: File)
>
> class File(database.Entity):
>     filename = Required(unicode)
>     directory = Required(lambda: Directory)
>
>     @property
>     def fullPath(self):
>         return os.path.join(self.directory.path, self.filename)
>
> # case 1
> with db_session:
>     fl = File[1]
> print fl.fullPath
>
> # case 2
> with db_session:
>     fl = File.select(lambda f: f.id==1).prefetch(File.directory).get()
> print fl.fullPath
>
> Case 1 will not work, case 2 will. So, I'd like to be able to specify that
> getting File always loads Directory, so that fullPath is available outside
> db_session. Is it (or will it be) possible?
> Somewhat related to this, it would be nice to be able to have 'calculated'
> attributes, which wouldn't be saved and loaded from the database, but would
> be serialized using to_dict(). I don't think it's possible now.
>
> Thanks, Tom
>
> _______________________________________________
> ponyorm-list mailing list
> ponyorm-list at ponyorm.com
> /ponyorm-list
>


-- 
Kind Regards,

Quazi Nafiul Islam
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </ponyorm-list/attachments/20141213/dc5199f7/attachment-0001.html>


More information about the ponyorm-list mailing list