Hate to be "that guy" who prematurely asks for help, then 10 mins later has 
found it. 

u1 = current_user
a1 = current_user.get_group_from_name('admin')
u1.group = a1
u1.save()

Hope this helps someone in the future, and sorry for this post.

On Friday, January 15, 2016 at 4:38:07 PM UTC+11, Mary Le Jane wrote:
>
> *How do you insert a row into an **association_table through the Parent 
> (class) child(variable) relationship.*
>
>
> This is pretty much my code (simplified)..
>
> association_table = Table('association', Base.metadata,
>     Column('left_id', Integer, ForeignKey('user.id')),
>     Column('right_id', Integer, ForeignKey('group.id'))
> ) 
> class User(Base): 
>     __tablename__ = 'user'
>     id = Column(Integer, primary_key=True)
>     group = relationship("Child",
>     secondary=association_table)
>     # user permissions
>
> class Group(Base):
>     __tablename__ = 'group'
>     id = Column(Integer, primary_key=True)
>     admin = db.Column(db.Boolean, default=False, nullable=False) mod = 
> db.Column(db.Boolean, default=False, nullable=False)
>
>     banned = db.Column(db.Boolean, default=False, nullable=False)
>
> Now in User I can *get *the group the user is in by doing 
> User.group.admin which goes in the association_table and searches for 
> queries:
>
> return self.group.query.filter(
>     group_users.c.group_id == group.id).count() > 0
>
>
> *But I have no idea how to insert a row into **association_table through the 
> group variable in Users. I am stumped.*
>
>

-- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to