RelationProperty(Page): NotionRubyMapping 解説 (48)

はじめに

NotionRubyMapping 解説の第48回目です。ページ側のプロパティを解説しています。今回は RelationProperty の変更です。現在はデータベース内の最初のページを使って説明していきます。

無題

irb(main):002> page = Page.find "https://www.notion.so/hkob/619a113814134c759773175ac988b96a?pvs=4"
=> NotionRubyMapping::Page-619a113814134c759773175ac988b96a

RelationProperty

まず、RelationProperty を取得します。

irb(main):004> rp = page.properties["One Way Relation"]
=>
#<NotionRubyMapping::RelationProperty:0x00000001029dd0c0

relation でリレーションの設定状況を確認できます。初期状態では空なので [] です。

irb(main):005> rp.relation
=> []

リレーション先のページを取得しておきます。

irb(main):007> owp = Page.find "https://www.notion.so/hkob/one-way-A-4b7ca127b49
14c13a74c9cd204fb7c61?pvs=4"
=> NotionRubyMapping::Page-4b7ca127b4914c13a74c9cd204fb7c61

relation = でリレーションを変更します。

irb(main):008> rp.relation = [owp.id]
=> ["4b7ca127b4914c13a74c9cd204fb7c61"]
irb(main):009> page.save
=> NotionRubyMapping::Page-619a113814134c759773175ac988b96a

設定されたリレーションがプロパティに設定されていることがわかります。

Relation
Untitled

おわりに

今回はページの RelationProperty の変更を説明しました。relation = でpage_id の配列を設定することでリレーションを設定することができます。

RelationProperty のマニュアルはこちらです。

RelationProperty

NotionRubyMapping解説