On Dec 12, 2012, at 10:07 AM, Peter Bunyan wrote:

> Much like FormAlchemy, I am trying to update my model from a post in a 
> generic manner. I'd like to find out if an Attribute(InstrumentedAttribute) 
> or its associated ColumnProperty is read-only. (please excuse ridiculous 
> example)
> 
> class Foo(Base):    
>     id = Column(Integer, primary_key=True)
>     name = Column(String)    
>     title = column_property(
>         select([func.UPPER(name)]).\
>         where(id==id)
>     )
> 
> Although setting 'title' will not cause an insert or update in the db 
> transaction, as it is a column_property, it will be settable. I'd like to not 
> set the attribute by using class_mapper(Foo).iterate_properties and being 
> able to determine that it was read_only. I do not ask lightly. I've read 
> extensively and looked through the source code and come up blank. I also 
> acknowledge that I wrote the model so I know it's read only - but I'd rather 
> be lazy and get my update to do the work - after all, that is why I'm using 
> such an excellent ORM.

the column_property has a .columns collection, of which it is usually just 
columns[0].   If columns[0] is present in the mapped table, the ORM will write 
to it; otherwise not.

So :

mapper = class_mapper(Foo)

table = mapper.local_table

property = Foo.name.property

expression = property.columns[0]

is_a_regular_mapped_column = table.c.contains_column(expression)





> 
> 
>  
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To view this discussion on the web visit 
> https://groups.google.com/d/msg/sqlalchemy/-/kFNDPpm3J9EJ.
> To post to this group, send email to sqlalchemy@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.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@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.

Reply via email to