Oleg Broytman wrote:

> On Sat, Jul 03, 2010 at 11:53:00AM +0200, Till Maas wrote:
>> class PackageUpdate(SQLObject):
>>     title            = UnicodeCol(notNone=True, alternateID=True)
>>     builds           = RelatedJoin("PackageBuild")#
>> 
>> class PackageBuild(SQLObject):
>>     nvr             = UnicodeCol(notNone=True, alternateID=True)
>>     package         = ForeignKey('Package')
>>     updates         = RelatedJoin("PackageUpdate")
>> 
>> class Package(SQLObject):
>>     name            = UnicodeCol(alternateID=True, notNone=True)
>>     builds          = MultipleJoin('PackageBuild',
>>     joinColumn='package_id')
>> 
>> 
>> This does not work,
> 
>    This declarations don't work? Or some code that uses them?

Sorry, I meant to add some example query here, but then realised that it is 
wrong anyhow.

This is the query that does not work unexpectedly, because 
query.append(PackageUpdate.q.builds == builds)
updates = PackageUpdate.select(AND(*query), orderBy=order).reversed()[:20]
creates this error:
AttributeError: PackageUpdate instance has no attribute 'builds'

>> but I cannot find any hint how I can use SQLObject to
>> get all package updates that contain builds for a certain package.
>> A SQL query would look like this:
>> 
>> SELECT package_update.title
>> FROM package_update, package_build_package_update, package_build, package
>> WHERE package_update.id = package_build_package_update.package_update_id
>> AND package_build.id = package_build_package_update.package_build_id
>> AND package_build.package_id = package.id
>> AND package.name = "bash";
> 
>    MultipleJoin works together with a corresponding ForeignKey. .select()
> doesn't take them into account. So either you iterate over Packages row by
> row and use .builds attribute of every row, or construct the query
> manually (and pass it to .select() call), or patch SQLObject so it
> understands joins better (and submit your patches for review).

Can you maybe give me a hint how to create the query or do I have to create 
the query completely as a string? Or is there some support for using custom 
queries in SQLObject that make SQL-Injections impossible e.g. by using 
prepared statements? Or is it possible to only add the part of the query 
needed for the joing and the package.name condition as a string but create 
the remainder of the query using SQL-constructs like AND(...), etc?

Regards
Till





------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to