Problem to load `included` relation data - return `[]` list in AshJson without actor
Hi, i have a problem with load data of relation table in Json API. consider just use
includes without paginated_includes (this problem still exist not just about paginated)
So i created this for :posts:
As you see i did read_action :public_list and this read_action is inside MishkaBlog.BlogPost like this:
Action:
policy:
Unfortunately it returns posts data [], but if i use these relation and send actor i have no problem
By the way public_list direct json api works as public without actor
why it happens?
Thank youSolution:Jump to solution
First I did this and did not work! the
i told ai to create a debug file instead of accessing from https://gist.github.com/shahryarjb/2e2e94288f8edd04bd69e6b76d292f35 ...
:<relationship_name>_join_relationship dose not work for me, idk
buti told ai to create a debug file instead of accessing from https://gist.github.com/shahryarjb/2e2e94288f8edd04bd69e6b76d292f35 ...
24 Replies
i even comment the other policies and use
it is very intersting when i put user token in header it loads data! without any permission, but without actor it does not work and return
[].
when i set the json_api do authorize? false it works, :)) how can just specific json api authorize? false not all of them?
and it is interesting it just prevents data for relation and the main request works! when loading relationships through AshJsonApi, even if the main action is public, the related resources are still being checked for authorization. 🥲
for example
Category (its data is returned) but the post of category is []
Could you please help me how to create public api?have you tried enabling policy logging https://hexdocs.pm/ash/policies.html#debugging-and-logging ?
I don't see anything that's obviously wrong here
I added it inside my config but it do not print anything. as you see it dose not print anything about forbidden
https://gist.github.com/shahryarjb/9e3a4ce200f17ebbd445c36a5d4c94db
as you see this still returns
If i login and request to it, it works, please consider the category loaded but the posts is
[]There is also a setting for successful logs. You set it to the log level and your logger needs to show that level
It should show you the action and checks it looked at to get to that result
Thank you now it prints
for category
for the category relation posts
the action read it
:public_listIf you set the log level to debug you should see the generated SQL, so far everything looks right
I saw this
https://gist.github.com/shahryarjb/9e3a4ce200f17ebbd445c36a5d4c94db
but idk , where is the problem! but with AI it says me
ON FALSE 🤔🤔🤔
I tested with actor too
https://gist.github.com/shahryarjb/9e3a4ce200f17ebbd445c36a5d4c94db
it has no on false
it is a bug in AshJson or Ash?if you try to do the same in iex, just calling the action with a load, does it happen there as well?
Yes this is the the log
https://gist.github.com/shahryarjb/9e3a4ce200f17ebbd445c36a5d4c94db
it has
And if i run time with actor work and has not
ON FALSE
like this:
it is same AshJson Request@Shahryar do you have any resources with a
bypass at the bottom of the list of policies?Sorry dear Zach i did not understand
but these are my 2 files policies
Main table (collection or category)
Relation table (posts)
Does this work if you do it in code? i.e
oh I see
you shared that already
Yes, the iex one has this problem too
with actor it is okey but without actor it is not okey and add
ON FALSEDo you have policies on the join resource?
MishkaBlog.PostCollection
just have this,
MishkaBlog.PostCollection, am i missing let it?
if this is the problem i should kill my self :))i should kill my selfdon't say that bro But yes taht is probably the problem You will want to set up a
join_relationship for this purpose
Now with that said I have something that will probably make your life way easier
It seems like what you want to do is make it so that if you can see one thing, you can read its relationship
Then you don't need public_list for relationships etc.i did this but dose not work
YOu will need it on both resources
the join resource and the destination resource
oh
also
that relationship name is wrong
The through relationship is autogenerated if you don't set it
You want something like that
Thank you Zach ♥️🙏🏻, i think i miss something here, i try and back to here again , so much thanks
for testing i put the
inside the joiner it works!
Yeah, so the join relationship is by default
:<relationship_name>_join_relationship
So likely just need to fix thatSolution
First I did this and did not work! the
i told ai to create a debug file instead of accessing from https://gist.github.com/shahryarjb/2e2e94288f8edd04bd69e6b76d292f35 After finding the name is
:<relationship_name>_join_relationship dose not work for me, idk
buti told ai to create a debug file instead of accessing from https://gist.github.com/shahryarjb/2e2e94288f8edd04bd69e6b76d292f35 After finding the name is
_join_assoc and code i change this
ah
on the destination resource, it is being access from the join resource
Oh, or maybe its not from the join resource I forget actualy
try both
For now it works perfectly 😂
Thank you so much, if i will try the thing you tell me
where i can send the pr for this doc?
Ash policy ?
the policies guide would be a good place yes