Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^4: DBIx::Class::ResultSet disired hash output including related items

by Veltro (Hermit)
on Feb 26, 2019 at 16:27 UTC ( [id://1230575]=note: print w/replies, xml ) Need Help??


in reply to Re^3: DBIx::Class::ResultSet disired hash output including related items
in thread DBIx::Class::ResultSet desired hash output including related items

That still prints only one 'Artist' row at a time and it only prints data from 'cds' ('shallow'). I am looking for something much more sophisticated than that in the sense recursiveness and flexibility (e.g. being able to specify multiple relations either one-to-many or many-to-many on different levels and keeping the full functionality of the ResultSet class).

  • Comment on Re^4: DBIx::Class::ResultSet disired hash output including related items

Replies are listed 'Best First'.
Re^5: DBIx::Class::ResultSet disired hash output including related items
by Your Mother (Archbishop) on Feb 26, 2019 at 16:50 UTC

    It seems like you want basically the same thing TO_JSON does. There are a couple helpers for that on the CPAN often used in conjunction with a JSON View in web apps. I usually write them manually and it's maybe a step too far, from flattening to serializing when you just want them flattened… These are fun but a bit time consuming to put together so I can't try today. If no one steps in, I'll give it a shot when I can.

      ...It seems like you want basically the same thing TO_JSON does...

      Well ultimately the goal is to turn the result into JSON data. After I have obtained the raw data structure I need to jsonify it so I the client app can receive it.

      ...couple helpers...

      Could you give some links so I can have a look what kind of helpers you are referring to?

      ...in conjunction with a JSON View in web apps...

      Are these JSON Views defined in the database? I basically decided to start using ORM so I keep all the logic inside the app and there would be no need to do anything in the database to keep it as simple as possible. E.g. Let's say I have a user table that contains a relation to user groups and another relation to permissions, then what you are suggesting, I would need to write different views for each type of output (>=4 views)? What I am looking for is so that I don't have to do that, pseudo code for each variant (outputting raw Perl array or hash/JSON) are:

      users->relation->groups, user->relation->groups, users->relation->permissions and user->relation->permissions (And if possible even using a filter:) user->relation->permissions->(name EQ 'Can add photo')
      That said however I may be looking at this the wrong way. Maybe JSON Views are the 'preferred' way to do it? In that case I would definitively like to know more about it. So in the mean while maybe you can also provide some links (Perl modules?) that deal with that topic?

      ...flattening to serializing...

      I find those terms always confusing. I basically just want to get only the table column names and the data it contains and turn that into JSON.

      ...so I can't try today...

      No worries, things don't have to be solved in one day. Any help is appreciated.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1230575]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2024-04-19 02:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found