Open TheFifthFreedom opened 9 years ago
Actually I figured it out in the end: for those who are curious, it turns out that the reason why Link
objects are committed after being instantiated inside of SearchEngineResultsPage
despite not being explicitly added to the SQLAlchemy session is because they share a many-to-one relationship with the SearchEngineResultsPage
table, as made explicit in their class parameters:
serp_id = Column(Integer, ForeignKey('serp.id'))
serp = relationship(SearchEngineResultsPage, backref=backref('links', uselist=True))
Therefore, if you wanted SampleTable
to be committed the same way, simply include some sort of relationship with SearchEngineResultsPage
(as long as it makes sense in your schema), such as this one-to-one relationship:
serp_id = Column(Integer, ForeignKey('serp.id'))
serp = relationship(SearchEngineResultsPage, backref=backref('tables', uselist=False))
This is more of a question rather than an issue per se: I'm trying to add an additional table to the database at runtime to store some particular results, and while I'm able to see the table in the output .db file, no results are ever committed to it, which means the table remains desperately blank. Here's what I did:
First, add a class to
database.py
Then instantiate that class inside of
SearchEngineResultsPage
'sset_values_from_parser
function:The reason I'm surprised to see
SampleTable
is because theSearchEngineResultsPage
object is committed to the sqlalchemy session inscraping.py
'sstore
function. Do you have some idea of what it is I'm doing completely wrong?