Francesc Romà i Frigolé wrote:
On Wed, Oct 20, 2010 at 2:57 PM, Peter Rabbitson <[email protected]
<mailto:rabbit%[email protected]>> wrote:
Francesc Romà i Frigolé wrote:
Hello,
I'm using overloaded column accessors as described in the
Cookbok
<http://search.cpan.org/%7Efrew/DBIx-Class-0.08123/lib/DBIx/Class/Manual/Cookbook.pod#OVERLOADING_METHODS>.
For a given row, I'd like to get a hash with all the column
names/value pairs like Row->get_columns returns. However,
get_columns returns the actual column values, not the ones
created with the custom overloaded accessors.
get_inflated_columns behaves the same way.
I don't believe you. Here is the implementation of get_inflated_columns
from the current CPAN version:
Thanks Peter for the prompt reply and your explanations. I believe you,
but I upgraded to the current CPAN version, and still see the same
result with get_inflated_columns, also the same happens in a different
computer with an older version (both running different versions of
ubuntu). It's very weird, but I haven't yet traced the issue any
further, so I can't give you any more insight.
Is there a better way of doing this? The reason why I want the
hash is to pass the data to my view in a Catalyst application.
Use
http://search.cpan.org/~frew/DBIx-Class-0.08123/lib/DBIx/Class/ResultClass/HashRefInflator.pm
<http://search.cpan.org/%7Efrew/DBIx-Class-0.08123/lib/DBIx/Class/ResultClass/HashRefInflator.pm>
HashRefInflator does indeed put the values given by the overloaded
accessors,
It shouldn't (as per the other reply).
I might be missing something here, but it seems to me that I can't use
HashRefInflator for a specific row, I have to use it for a result set.
Correct, though you can add HRI as an ttribute to find()
It's not a big deal, I can just create the hash myself, I'm just
concerned I might be doing something wrong.
For what you want to do it would be your best bet.
BTW, the documentation of Row->get_column says "Returns a raw
column value from the row object, if it has already been fetched
from the database or set by an accessor." Which made me think it
would do what I need, but it doesn't.
Yes, it returns the raw value, regardless of what transformations took
place, it reaches into the object itself. Please suggest better wording
for above piece of documentation (or just send a github pull req :)
Well, now that I'm reading it again it seems more clear :)
Still suggestions to make it even clearer are not a bad thing :)
To illustrate my point, I took the code in
DBIx::Class::Manual::Example, and added the following accessor
in the result Track:
...
As you can see, the overloaded accessor works with the row
object, but is not used by get_columns.
Yes, expected and by design.
Fine, but I get the same result with get_inflated_results
while (my $track = $rs->next) {
print $track->title . "\n";
my $track_href = { $track->get_inflated_columns };
print "inflated: " . $track_href->{title} . "\n";
}
---
Leave Me Alone -> my favourite song!
inflated: Leave Me Alone
Smooth Criminal -> my favourite song!
inflated: Smooth Criminal
Dirty Diana -> my favourite song!
inflated: Dirty Diana
I... hm... is it the addition of 'my fav song' that is missing?
Can you show me how you are appending it?
I know you won't believe it :p It's ok, I'm actually not interested in
the inflated values, I'm just mentioning it for completeness, I need the
hash for a JSON view.
It's not impossible that this is in fact a bug, thus making sure I am
not missing a glaring error somewhere. Care to elaborate?
Cheers
_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/[email protected]