On Aug 9, 2010, at 5:13 AM, zzer0 wrote:
> Hi there.
>
> I have 2 declarative_base classes: Person and Inquiry. I have created
> a relationship in Inquiry with a backref to Person.
> When observing the an Inquiry object the person variable correctly
> points to Person, however when observing Person objects I always get
> an empty list in inquiries variable.
The code below is fine so the origin of the issue probably lies within
configuration or usage that is not illustrated here.
> Also on a different topic I have not been able to figure out how to do
> Adjacency List Relationship here to backref Person to Person as you
> can see in the referred_by variable, which I commented out.
Person needs to be passed as a late-resolved string expression here, and the
many-to-one side needs the "remote_side" argument, in this case :
referred_by = relationship("Person", remote_side=id, backref =
backref("people_referred", order_by = id))
> Any help would be appreciated greatly - thank you
>
> class Person(Base):
> __tablename__ = "people"
>
> id = Column(Integer, primary_key=True)
> names = Column(String)
> surname = Column(String)
> mobile_number = Column(Integer)
> land_number = Column(Integer)
> email = Column(String)
> address_id = Column(Integer,ForeignKey("addresses.id"))
> organization_id = Column(Integer,ForeignKey("organizations.id"))
> net_worth = Column(Integer)
> annual_net_income = Column(Integer)
> work_position_id =
> Column(Integer,ForeignKey("people_work_positions.id"))
> rapport = Column(Integer)
> leads_generator = Column(Integer)
> notes = Column(String)
> referred_by_id = Column(Integer,ForeignKey("people.id"))
> designation_id =
> Column(Integer,ForeignKey("people_designations.id"))
> other_contacts = Column(String)
> date_of_birth = Column(Integer)
> system_folder = Column(String)
> lead_source_id = Column(Integer,ForeignKey("leads_sources.id"))
>
> address = relationship(Address, backref = backref("people",
> order_by = id))
> organization = relationship(Organization, backref =
> backref("people", order_by = id))
> work_position = relationship(WorkPosition, backref =
> backref("people", order_by = id))
> designation = relationship(Designation, backref =
> backref("people", order_by = id))
> lead_source = relationship(LeadSource, backref = backref("people",
> order_by = id))
> #referred_by = relationship(Person, backref =
> backref("people_referred", order_by = id))
>
>
> class Inquiry(Base):
> __tablename__ = "inquiries"
>
> id = Column(Integer, primary_key=True)
> projected_close_date = Column(Date)
> closed_date = Column(Date)
> opened_date = Column(Date)
> service_start_date = Column(Date)
> process_step_id = Column(Integer,
> ForeignKey("inquiries_process_steps.id"))
> commission = Column(Integer)
> cost = Column(Integer)
> forecast = Column(Integer)#1-5 10,30,50,70,90 %
> person_id = Column(Integer, ForeignKey("people.id"))
> organization_id = Column(Integer, ForeignKey("organizations.id"))
> product_service_id = Column(Integer,
> ForeignKey("products_services.id"))
> notes = Column(String)
> lost_date = Column(Date)
>
> process_step = relationship(ProcessStep, backref =
> backref("inquiries", order_by = id))
> person = relationship(Person, backref = backref("inquiries",
> order_by = id))
> organization = relationship(Organization, backref =
> backref("inquiries", order_by = id))
> product_service = relationship(ProductService, backref =
> backref("inquiries", order_by = id))
>
> --
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/sqlalchemy?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.