Mapping a Subset of Table Columns

__flow__·2022년 7월 10일
0

Python | SQLAlchemy

목록 보기
1/1
post-thumbnail

Mapping a Subset of Table Columns


(SQLAlchemy ORM > ORM Mapped Class Configuration > Mapping Columns and Expressions > Mapping Table Columns)


Sometimes, a Table object was made available using the reflection process descirbed at Reflecting Database Objects to load the table's structure from the database. For such a table that has lots of columns that don't need to be referenced in the application.


For example:

class User(Base):
	__table__ = user_table
    __mapper_args__ = {
    	'include_properties': ['user_id', 'user_name']
 	}

...will map the User class to the user_table table, only including the user_id, and user_name columns - the rest are not referenced.


Similarly:

class Address(Base):
	__table__ = address_table
    __mapper_args__ = {
    	'exclude_properties': ['street', 'city', 'state', 'zip']
    }

...will map the Address class to the address_table table, including all columns present excpet street, city, state, and zip.


When this mapping is used, the columns that are not included will not be referenced by in any SELECT statements emitted by Query, nor will there be any mapped attribute on the mapped class which represents the column; assigning an attribute of that name will have no effect beyond that of a normal Python attribute assignment.


In some cases, multiple columns may have the same name, such as when mapping to a join of two or more tables that share some column name. include_properties and exclude_properties can also accommodate Column objects to more accurately describe which columns should be included or excluded:

class UserAddress(Base):
	__table__ = user_table.join(addresses_table)
    __mapper_args__ = {
    	'exclude_properties': [address_table.c.id],
        'primary_key': [user_table.c.id]
    }

Note
insert and update defaults configured on individual Column objecs, i.e. those described at Column INSERT/UPDATE Defaults including those configured by the Column.default, Column.onupdate, Column.server_default and Column.server_onupdate parameters, will continue to function normally even if those Column objects are not mapped. This is because in the case of Column.default and Column.onupdate, the Column object is till present on the underlying Table, thus allowing the default functions to take place when the ORM emits an INSERT or UPDATE, and in the case of Column.server_default and Column.server_onupdate, the relational database itself emits these defaults as a server side behaivor.



__flow__ comments

  • 무슨 말인지 잘 모르겠다. TWIL에서 다시 읽어보자. (2022.07.11.)
profile
fullcycle(fullstack), python/javascript, keepflowin, he/him

7개의 댓글

comment-user-thumbnail
2023년 12월 6일

These are easily seen when referencing tables. Only when you clearly understand the nature can you easily manipulate to rearrange the correct geometry dash lite order. Your sharing brings effective knowledge and is worth discussing.

답글 달기
comment-user-thumbnail
2024년 1월 16일

The (Mahipalpur Call Girls) https://www.mahipalpurescorts.co.in/ is a wonderful choice for people who want to spend time with a bunch of young females and have the most fun possible. We are available 24 hours a day, seven days a week, so you can call them whenever it is convenient for you.

답글 달기
comment-user-thumbnail
2024년 2월 8일

When you talk about the excellence and sophistication in service, then Goa Escorts will surely be considered at the top of the list.
https://ekcochat.com/read-blog/49347
https://www.finlandnhlforum.com/read-blog/9006
https://tweecampus.com/read-blog/43808
https://app.socie.com.br/read-blog/65302
https://americanwomenorg.com/read-blog/25610
https://wiwonder.com/read-blog/27190
https://www.campusacada.com/blogs/96612/Call-Girls-Service-in-Goa
https://myworldgo.com/blog/85174/goa-escorts-service-book-female-escort-in-goa-at-low-cost
https://facelore.com/read-blog/32917_goa-escorts-hire-escorts-service-in-goa-at-your-hotel-room.html
https://social.kubo.chat/read-blog/49721_goa-escorts-high-profile-goa-escort-service-24-7.html
https://hallbook.com.br/blogs/182585/Goa-Escorts-Service-91-9999999999-VIP-Escort-Hotel-room-COD
https://menagerie.media/index.php?link1=read-blog&id=39578
https://www.29chat.com/read-blog/20862_goa-escorts-amp-hot-call-girls-in-goa-sexy-escorts-in-goa.html
https://freshsites.download/socialwow/read-blog/29433_goa-hottest-escorts-top-amp-for-best-hotel-or-room-24-7.html
https://tannda.net/read-blog/43736_100-verified-goa-escorts-service-24x7-free-delivery.html
https://www.wowonder.xyz/read-blog/39412_goa-escorts-service-get-100-real-picture-escorts-in-goa.html
https://www.exoltech.us/blogs/165477/Escorts-in-Goa-Goa-Beach-Escorts-Service-2499-With-Room
https://www.addonface.com/read-blog/32007_goa-escorts-100-real-photo-039-s-of-best-escort-in-goa.html
https://www.djjmeets.com/blogs/130533/Goa-Escorts-Service-VIP-and-Independent-Escorts-in-Goa
https://thehealthbridges.com/read-blog/11709_goa-escorts-service-rate-4500-cash-payment-24-7.html
https://insta.tel/read-blog/30991_escorts-goa-service-4500-to-25k-with-ac-room.html
https://kansabook.com/read-blog/119426_goa-escorts-escorts-service-rate-4500-cash-payment-24-7.html
https://chutpatti.com/read-blog/8136_best-goa-escorts-services-5k-50k-escorts-in-goa-free-cod.html
https://www.dostally.com/read-blog/157181_goa-escorts-book-escort-in-goa-24-7-service.html
https://socialblast.club/read-blog/27974_goa-escorts-service-9999999999-call-girls-starts-rs-2500-only.html

답글 달기
comment-user-thumbnail
2024년 2월 15일

Escort in Butterfly Beach can easily steal the limelight in any party and prove to be a perfect arm candy thereby making you feel proud and better in their presence and companionship.

답글 달기
comment-user-thumbnail
2024년 2월 27일

We, in Noida Escorts, are highly established professionals when it comes to delivering our services. We will assure you seamless transactions and smooth communications in our team. We believe that your exclusivity is important, and we want to fully entrench this with your team of our executive customer service that will give the security and necessary business information for our clientele.

https://facelore.com/read-blog/36008_noida-escorts-girls-5-6k-with-cod-free-delivery-service.html
https://myworldgo.com/blog/87350/beautiful-and-alluring-noida-escorts-call-girls
https://menagerie.media/index.php?link1=read-blog&id=41387_call-girls-in-noida-escort-service-3500-with-free-delivery.html
https://www.29chat.com/read-blog/26443_independent-escort-service-in-noida-5999-with-hotel.html
https://tannda.net/read-blog/45841_noida-escort-service-in-rate-3000-free-home-delivery.html
https://social.kubo.chat/read-blog/53119_noida-escorts-girls-5-6k-with-cod-free-delivery-service.html
https://freshsites.download/socialwow/read-blog/31119_noida-escorts-service-24x7-at-your-budget-3900-cash.html
https://www.exoltech.us/blogs/174973/Noida-Escorts-4999-with-free-24x7-Home-Delivery-Service
https://kansabook.com/read-blog/122076_noida-escort-service-rate-3500-with-room-free-home-delivery.html
https://www.addonface.com/read-blog/35222_get-only-cash-delivery-escorts-in-noida-starting-2300.html
https://www.djjmeets.com/blogs/132548/Noida-Escorts-5k-25k-Escort-Service-In-Noida-24-7
https://thehealthbridges.com/read-blog/13279_escorts-in-noida-escorts-service-noida-2500.html
https://insta.tel/read-blog/34612_escort-and-call-girl-service-in-noida-cash-only.html
https://www.dostally.com/read-blog/161985_noida-escorts-4999-with-free-24x7-home-delivery-service.html
https://chutpatti.com/read-blog/10344_noida-escorts-independent-escorts-service-24-7-available.html
https://www.merexpression.com/read-blog/141519_noida-escorts-feel-relax-mind-amp-body-call-girls-noida.html
https://onetable.world/read-blog/43969_escorts-in-noida-2500-room-free-home-delivery.html
https://bicycle.one/read-blog/78082_noida-escorts-noida-call-girls-whatsapp-number.html
https://www.gift-me.net/blogs/145034/Noida-Escorts-Escort-Service-in-Noida-3500-With-Free-Hotel
https://chatterchat.com/read-blog/12487_call-girls-in-noida-4999-with-free-24x7-home-delivery.html
https://mimedia.in/read-blog/11950_noida-call-girls-24x7-escorts-service-available-near-you.html
https://www.diccut.com/read-blog/13812_noida-escorts-escort-service-in-3500-with-free-hotel.html
https://www.pickmemo.com/read-blog/270511_hot-noida-escort-services-available-24-7-from-julie-oberoi.html
https://ekonty.com/blogs/view/42662
https://bib.az/read-blog/8637_noida-escorts-service-outcall-independent-call-girls.html
https://www.snipesocial.co.uk/blogs/374252/Noida-Escorts-3K-Per-Night-Escort-Service-in-Noida
https://www.cyberpinoy.net/read-blog/15468_low-rate-call-girls-escort-service-in-noida.html
https://say.la/read-blog/23180_book-escorts-in-noida-3000-free-hotels-delivery.html
https://usame.life/read-blog/24942_find-noida-escorts-service-meet-our-call-girls-24-7.html
https://kryza.network/read-blog/14222_noida-escorts-service-5k-25k-escort-service-in-noida-24-7.html
https://www.friend007.com/read-blog/115206_noida-escort-service-in-rate-3000-free-home-delivery.html
https://connected.linkspreed.com/read-blog/41285_escorts-in-noida-rate-2500-with-free-home-delivery.html
http://social.marksedgwick.net/blogs/40602/Escorts-in-Noida-Escort-INCall-3500-Pay-to-Cash
https://click4r.com/posts/g/14713787/

답글 달기
comment-user-thumbnail
2024년 3월 7일

One night stands, you can always fancy your chances to keep the excitement going. The hired Delhi Escorts will showcase their hotness to make you desperate and won’t let your sexual desire affect the physical relationship.

답글 달기
comment-user-thumbnail
2024년 3월 7일

The best way to avoid such disgraceful moment is to book an educated, beautiful, and high-profile Aerocity Escort Service. The well-cultured women will be suitable for partying and events to bring unforgettable experiences with their sweet talk and attention. Moreover, they are simply fire on bed with their seductive and hot services.

답글 달기