[sqlalchemy] Re: double data insert in many-to-many relations

2010-09-17 Thread Dobrysmak
Okay, i have got a stupid question.
i have got something like this:

result = Session.query(Messages).filter(
  Messages.from_user == 1).filter(
User.id != 1).all()

This query is supposed to get all the messages ( Messages table) that
have the senders id (from_user) but select ONLY this messages that are
connected to all users except user with id = 1.
This tables are many-to-many( Messages, Messages_Users, Users ). The
relationship is set correctly.

Is this even possible? ;-)

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



[sqlalchemy] Re: double data insert in many-to-many relations

2010-09-01 Thread Dobrysmak
Hi.
Okay, thanks ;-)

This solution seems pretty good, but can i associate two records from
MESSAGES_USERS_RECIEVING and MESSAGES_USERS_SENDING to one (the same)
message record in messages table? If yes, then how?



On 1 Wrz, 13:04, Francisco Souza franci...@franciscosouza.net wrote:
  On Wed, Sep 1, 2010 at 5:14 AM, Dobrysmak lukasz.szyman...@gmail.comwrote:
  [...]

  ConcurrentModificationError: Updated rowcount 0 does not match number
  of objects updated 1

  Mabey there's a better way to do this?
  Anyone have a clue?

 Hi :)

 you should have to many-to-many relationships and two association tables:
 messages_users_receiving and messages_users_sending.

 So you configure two many to many relationships with different secondary
 tables.

 Cheers,
 Francisco Souza
 Software developer at Giran and also full time
 Open source evangelist at full time

 English:http://www.franciscosouza.net
 Portuguese:http://www.franciscosouza.com.br
 Twitter: @franciscosouza
 +55 27 3026 0264

 On Wed, Sep 1, 2010 at 5:14 AM, Dobrysmak lukasz.szyman...@gmail.comwrote:



  Hi.
  I'm building a db with many-to-many relations, ex.
  * Table Users
  * Table Messages
  * Table Messages_Users

  when the users sends a message to other users i'm inserting that
  message to the db like so,

  *Messages - insert 1 row with the message, values ( title, text ,
  date, etc... )

  *Messages_Users - insert 2 rows ( one with connetion to the sending
  user and message,second with connection to the recieving user and
  message), values ( user_id, message_id, id_from, id_to, etc...)

  at the process of inserting the second row to the Messages_Users table
  i'm getting an error,

  ConcurrentModificationError: Updated rowcount 0 does not match number
  of objects updated 1

  Mabey there's a better way to do this?
  Anyone have a clue?

  --
  You received this message because you are subscribed to the Google Groups
  sqlalchemy group.
  To post to this group, send email to sqlalch...@googlegroups.com.
  To unsubscribe from this group, send email to
  sqlalchemy+unsubscr...@googlegroups.comsqlalchemy%2bunsubscr...@googlegrou 
  ps.com
  .
  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 sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.



Re: [sqlalchemy] Re: double data insert in many-to-many relations

2010-09-01 Thread Francisco Souza

 On Wed, Sep 1, 2010 at 8:59 AM, Dobrysmak lukasz.szyman...@gmail.comwrote:
 Hi.
 Okay, thanks ;-)

 This solution seems pretty good, but can i associate two records from
 MESSAGES_USERS_RECIEVING and MESSAGES_USERS_SENDING to one (the same)
 message record in messages table? If yes, then how?


Yes, you can! ;)

Looking on design, you can have the message Hello sent from John (a
user) to Mary (other user), then you will have the following rows on
database:

*Table messages:*
ID TEXT
1   Hello

*Table users:*
ID NAME
1   John
2   Mary

*Table messages_users_receiving:*
ID MESSAGE_IDUSER_ID
1  1  2 (Mary)

*Table messages_users_sending
*ID MESSAGE_IDUSER_ID
1   1 (the same)   1 (John)

But here you can check your model: a message can be sent to one or more
users, but can a message be sent from more than one user? If a message is
sent only by a user, you should have a many to one relationship between
message and user (the sender), and a many to many relationshop between the
same tables (the receivers, that can be one or more users).

Best regards,
Francisco Souza
Software developer at Giran and also full time
Open source evangelist at full time

English: http://www.franciscosouza.net
Portuguese: http://www.franciscosouza.com.br
Twitter: @franciscosouza
+55 27 3026 0264


On Wed, Sep 1, 2010 at 8:59 AM, Dobrysmak lukasz.szyman...@gmail.comwrote:

 Hi.
 Okay, thanks ;-)

 This solution seems pretty good, but can i associate two records from
 MESSAGES_USERS_RECIEVING and MESSAGES_USERS_SENDING to one (the same)
 message record in messages table? If yes, then how?



 On 1 Wrz, 13:04, Francisco Souza franci...@franciscosouza.net wrote:
   On Wed, Sep 1, 2010 at 5:14 AM, Dobrysmak lukasz.szyman...@gmail.com
 wrote:
   [...]
 
   ConcurrentModificationError: Updated rowcount 0 does not match number
   of objects updated 1
 
   Mabey there's a better way to do this?
   Anyone have a clue?
 
  Hi :)
 
  you should have to many-to-many relationships and two association tables:
  messages_users_receiving and messages_users_sending.
 
  So you configure two many to many relationships with different secondary
  tables.
 
  Cheers,
  Francisco Souza
  Software developer at Giran and also full time
  Open source evangelist at full time
 
  English:http://www.franciscosouza.net
  Portuguese:http://www.franciscosouza.com.br
  Twitter: @franciscosouza
  +55 27 3026 0264
 
  On Wed, Sep 1, 2010 at 5:14 AM, Dobrysmak lukasz.szyman...@gmail.com
 wrote:
 
 
 
   Hi.
   I'm building a db with many-to-many relations, ex.
   * Table Users
   * Table Messages
   * Table Messages_Users
 
   when the users sends a message to other users i'm inserting that
   message to the db like so,
 
   *Messages - insert 1 row with the message, values ( title, text ,
   date, etc... )
 
   *Messages_Users - insert 2 rows ( one with connetion to the sending
   user and message,second with connection to the recieving user and
   message), values ( user_id, message_id, id_from, id_to, etc...)
 
   at the process of inserting the second row to the Messages_Users table
   i'm getting an error,
 
   ConcurrentModificationError: Updated rowcount 0 does not match number
   of objects updated 1
 
   Mabey there's a better way to do this?
   Anyone have a clue?
 
   --
   You received this message because you are subscribed to the Google
 Groups
   sqlalchemy group.
   To post to this group, send email to sqlalch...@googlegroups.com.
   To unsubscribe from this group, send email to
   sqlalchemy+unsubscr...@googlegroups.comsqlalchemy%2bunsubscr...@googlegroups.com
 sqlalchemy%2bunsubscr...@googlegrou ps.com
   .
   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 sqlalch...@googlegroups.com.
 To unsubscribe from this group, send email to
 sqlalchemy+unsubscr...@googlegroups.comsqlalchemy%2bunsubscr...@googlegroups.com
 .
 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 sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.