bmuller / twistar

Twistar is an object-relational mapper (ORM) for Python that uses the Twisted library to provide asynchronous DB interaction.
http://findingscience.com/twistar
Other
132 stars 38 forks source link

How to make a join statement #72

Closed aaleotti-unimore closed 7 years ago

aaleotti-unimore commented 7 years ago

Hi, I read the documentation but there's no sign how to make a join statement (or using implicit notation, select from two different tables using a where clause). is there a proper way rather than directly with low level sql statements?

bmuller commented 7 years ago

http://findingscience.com/twistar/doc/relationship_examples.html

aaleotti-unimore commented 7 years ago

so there's no way to make a relationship that's not based on the id colum of a table?

bmuller commented 7 years ago

I think you can specify the join columns

On Oct 13, 2016, at 08:15, aaleotti-unimore notifications@github.com wrote:

so there's no way to make a relationship that's not based on the id colum of a table?

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub, or mute the thread.

aaleotti-unimore commented 7 years ago

can you tell where it's explained? because it's not specified anywhere which are the acceptable arguments for the optional dictionary of the HASONE / HASMANY / etc class variables The example only says to refer to the Relationships class but in the docs there's nothing to define the columns.

I used the line as shown in the example:

class Comment(DBObject):
     HASONE = [{'name': 'User', 'class_name': 'user', foreign_key: 'user_id'}]

class User(DBObject):
     pass

but I can't specify which is the column in the Comment class i want to join in the User class (named user_id as well)

can I use this like shown in this ruby-on-rails example i found on Stackfoverflow?

class Client < ActiveRecord::Base
  belongs_to :region, foreign_key: 'location_id'

class Region < ActiveRecord::Base
  has_many :clients, foreign_key: 'place_id'

Thanks for your support