> On 22 Jan 2014, at 22:32, Jonathan Vanasco <[email protected]> wrote:
>
> Would an association proxy help ?
>
> http://docs.sqlalchemy.org/en/rel_0_9/orm/extensions/associationproxy.html
>

Thanks for the suggestion. In fact I'm already using association
proxies in a couple of places, but I'm not sure it'll help in this
case, because what I'm really after is SA's ability to eager load the
relationship. Despite the intermediate tables, this is actually a 1-1
relationship.

For anyone who is interested, the tables I'm working with represent
users (table A) who belong to companies (table B). Companies have a
foreign key to a set of terms and conditions that their members must
accept (table D, different companies may have different terms). The
terms table has a version number column to keep track of when the
terms are updated.

Table C keeps track of the acceptances, with foreign keys to the user
and terms tables, and also the version of the terms at the time they
were accepted.

The relationship I'm trying to model is the "current valid
acceptance", ie the row in table C that points to the user, to the
same set of terms as the company that the user belongs to, and has the
same version number that the terms has. The join conditions look
something like:

User.companyid == Company.id
Company.termsid == Terms.id
Acceptance.userid == User.id
Acceptance.termsid == Company.termsid
Acceptance.termsversion == Terms.version

And in fact one more condition as well: DATEDIFF(NOW(),
Acceptance.datetime) <= 365

If this relationship finds a matching row, the user has accepted the
terms in the last year. But if no row matches, the user must
re-accept.

I'll work up the test script tomorrow to clarify.

Thanks,

Simon

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to