Using save_on_init with relationships

21 views
Skip to first unread message

Iwan Vosloo

unread,
Mar 19, 2013, 7:10:05 AM3/19/13
to sqle...@googlegroups.com
Hello.

From the little example below, it seems that setting save_on_init=False on a class is ignored
when that class is pointed to by a relationship from another object which IS saved (or selected
from the database, for that matter).

Is this intended behaviour?

See the example below. If you comment out the "addresses" relationship on AddressBook (see #1), 
it works as intuitively expected.


#----------[example START]----------------------------
import elixir

elixir.metadata.bind = 'sqlite://'

class AddressBook(elixir.Entity):
    addresses  = elixir.OneToMany(u'Address')      #1
    pass


class Address(elixir.Entity):
    elixir.using_mapper_options(save_on_init=False)
    address_book  = elixir.ManyToOne(u'AddressBook')

elixir.setup_all()
elixir.create_all()


book = AddressBook()

new_address = Address(address_book=book)
assert not Address.query.all()                               # breaks here

#----------[example END]----------------------------

Iwan Vosloo

unread,
Mar 19, 2013, 7:11:42 AM3/19/13
to sqle...@googlegroups.com
This is with elixir 0.7.1 and sqlalchemy 0.7.7 on Python 2.7.
Reply all
Reply to author
Forward
0 new messages