Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The accessor created by deftable cannot access dao. #79

Open
cxxxr opened this issue Mar 6, 2021 · 1 comment
Open

The accessor created by deftable cannot access dao. #79

cxxxr opened this issue Mar 6, 2021 · 1 comment
Labels

Comments

@cxxxr
Copy link
Collaborator

cxxxr commented Mar 6, 2021

$ createdb mito-example
(ql:quickload :mito)

(mito:deftable parent ()
  ())

(mito:deftable child ()
  ((parent :col-type parent)))

(mito:connect-toplevel :postgres :database-name "mito-example")

(mapc #'mito:execute-sql (mapcan #'mito:table-definition '(parent child)))

(mito:create-dao 'child :parent (mito:create-dao 'parent))

(child-parent (mito:find-dao 'child)) ;; The slot PARENT is unbound in the object

;; Specify the accessor explicitly
(mito:deftable child ()
  ((parent :col-type parent :accessor child-parent)))

(child-parent (mito:find-dao 'child)) ;; => #<PARENT {1005BD41D3}>
@cxxxr cxxxr added the bug label Mar 6, 2021
@cxxxr cxxxr self-assigned this Mar 6, 2021
@cxxxr cxxxr removed their assignment Mar 21, 2021
@vindarel
Copy link
Contributor

vindarel commented Nov 4, 2024

This is now either resolved either slightly different.

(mito:deftable parent ()
  ())

(mito:deftable child ()
  ((parent :col-type parent)))

(mito:connect-toplevel :sqlite3 :database-name "mito-example.db")

(mapc #'mito:execute-sql (mapcan #'mito:table-definition '(parent child)))

(mito:create-dao 'child :parent (mito:create-dao 'parent))

(mito:find-dao 'child)
;; => <CHILD object>

(describe *)
#<CHILD {100809C873}>
  [standard-object]

Slots with :INSTANCE allocation:
  CREATED-AT                     = @2024-11-04T18:26:48.822588+01:00
  UPDATED-AT                     = @2024-11-04T18:26:48.822588+01:00
  SYNCED                         = T
  ID                             = 1
  PARENT                         = #<unbound slot>
  PARENT-ID                      = 1

=> parent is unbound, the parent-id is OK,

there is no parent accessor but the child-parent accessor works:

(child-parent (mito:find-dao 'child))
;; =>
#<PARENT {1009083C63}>

continuing

;; Specify the accessor explicitly
(mito:deftable child ()
  ((parent :col-type parent :accessor child-parent)))

(child-parent (mito:find-dao 'child)) ;; => #<PARENT {1005BD41D3}>
;; and now
(parent (mito:find-dao 'child)) ;; => same

in addition there is now the parent accessor.


However all is not clear when I try accessors on my own projects, specially when the :slot-type is (or :null :a-table), afaik.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants