PeopleProperty(Page): NotionRubyMapping 解説 (46)

はじめに

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

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

PeopleProperty

まず、PeopleProperty を取得します。

irb(main):003> pp = page.properties["People"]
=>
#<NotionRubyMapping::PeopleProperty:0x00000001242d8ac8

people で人の設定状況を確認できます。初期状態では空です。

irb(main):004> pp.people
=> []

add_person で人を代入できます。人の id を取得するのは大変なので、CreatedBy プロパティに入っている私を登録します。今回は add_person に UserObject をそのまま渡していますが、user_id の文字列を渡してもよいです。

irb(main):009> user = page.properties["CreatedBy"].created_by
=> NotionRubyMapping::UserObject-2200a9116a9644bbbd386bfb1e01b9f6
irb(main):010> pp.add_person user
=> [NotionRubyMapping::UserObject-2200a9116a9644bbbd386bfb1e01b9f6]
irb(main):011> page.save
=> NotionRubyMapping::Page-619a113814134c759773175ac988b96a

設定された人がプロパティに設定されていることがわかります。

PersonProperty

おわりに

今回はページの PeopleProperty の変更を説明しました。add_person でユーザを追加することができます。

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

PeopleProperty

NotionRubyMapping解説