how to determine column is inflatable?

9 messages Options
Embed this post
Permalink
Carl Franks

how to determine column is inflatable?

Reply Threaded More More options
Print post
Permalink
Is it okay to use $result_source->column_info('name')->{_inflate_info}
to test whether a column is inflatable / deflatable?
It seems a bit too reliant on internals, to me.

Or should there be a has_inflatable_column('name') method?

(and is that what it should be called? do we really also need a
'has_deflatable_column' too?)

If someone makes a call, I'll write up a patch for it.

Carl

_______________________________________________
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/dbix-class@...
Ash Berlin

Re: how to determine column is inflatable?

Reply Threaded More More options
Print post
Permalink

On 29 Jan 2009, at 22:03, Carl Franks wrote:

> Is it okay to use $result_source->column_info('name')->{_inflate_info}
> to test whether a column is inflatable / deflatable?
> It seems a bit too reliant on internals, to me.
>
> Or should there be a has_inflatable_column('name') method?
>
> (and is that what it should be called? do we really also need a
> 'has_deflatable_column' too?)
>
> If someone makes a call, I'll write up a patch for it.
>
> Carl
>

There doesn't seem to be a public way to determine this, and indeed  
accessing anything starting with an _ indicates badness.

First things first - what exactly do you care if a column is inflated  
or not?

Secondly, do you treat relationships as inflated or not?

-ash

_______________________________________________
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/dbix-class@...
Carl Franks

Re: how to determine column is inflatable?

Reply Threaded More More options
Print post
Permalink
2009/1/29 Ash Berlin <[hidden email]>:

>
> On 29 Jan 2009, at 22:03, Carl Franks wrote:
>
>> Is it okay to use $result_source->column_info('name')->{_inflate_info}
>> to test whether a column is inflatable / deflatable?
>> It seems a bit too reliant on internals, to me.
>>
>> Or should there be a has_inflatable_column('name') method?
>>
>> (and is that what it should be called? do we really also need a
>> 'has_deflatable_column' too?)
>>
>> If someone makes a call, I'll write up a patch for it.
>>
>> Carl
>>
>
> There doesn't seem to be a public way to determine this, and indeed
> accessing anything starting with an _ indicates badness.
>
> First things first - what exactly do you care if a column is inflated or
> not?

In HTML-FormFu-Model-DBIC, I can't just use get/set_column(),
otherwise in/deflators won't get called.
So I've had to document that people can't name fields after DBIC
built-in methods such as 'delete', otherwise when we call $row->$name
it'll trash your db.

What I'd like to do is allow the use of any name, by doing something like this:

    $value = $row->result_source->has_inflated_column
        ? $row->get_inflated_column( $name )
        : $row->get_column( $name );

    $row->result_source->has_inflated_column
        ? $row->set_inflated_column( $name, $value )
        : $row->set_column( $name, $value );

I can't just use get/set_inflated_column() for everything, as it
croaks if there's no in/deflator for a column.

> Secondly, do you treat relationships as inflated or not?

'fraid I'm not really sure what that means.
I generally just use something like
    @rows = $row->$rel;

Cheers,
Carl

_______________________________________________
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/dbix-class@...
Peter Rabbitson-2

Re: how to determine column is inflatable?

Reply Threaded More More options
Print post
Permalink
Carl Franks wrote:

> 2009/1/29 Ash Berlin <[hidden email]>:
>> On 29 Jan 2009, at 22:03, Carl Franks wrote:
>>
>>> Is it okay to use $result_source->column_info('name')->{_inflate_info}
>>> to test whether a column is inflatable / deflatable?
>>> It seems a bit too reliant on internals, to me.
>>>
>>> Or should there be a has_inflatable_column('name') method?
>>>
>>> (and is that what it should be called? do we really also need a
>>> 'has_deflatable_column' too?)
>>>
>>> If someone makes a call, I'll write up a patch for it.
>>>
>>> Carl
>>>
>> There doesn't seem to be a public way to determine this, and indeed
>> accessing anything starting with an _ indicates badness.
>>
>> First things first - what exactly do you care if a column is inflated or
>> not?
>
> In HTML-FormFu-Model-DBIC, I can't just use get/set_column(),
> otherwise in/deflators won't get called.
> So I've had to document that people can't name fields after DBIC
> built-in methods such as 'delete', otherwise when we call $row->$name
> it'll trash your db.
>
> What I'd like to do is allow the use of any name, by doing something like this:
>
>     $value = $row->result_source->has_inflated_column
>         ? $row->get_inflated_column( $name )
>         : $row->get_column( $name );
>
>     $row->result_source->has_inflated_column
>         ? $row->set_inflated_column( $name, $value )
>         : $row->set_column( $name, $value );
>
> I can't just use get/set_inflated_column() for everything, as it
> croaks if there's no in/deflator for a column.

Smells like a misdesign... Shall we fix this or was there a reason to
have it this way?



_______________________________________________
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/dbix-class@...
Ash Berlin

Re: how to determine column is inflatable?

Reply Threaded More More options
Print post
Permalink
In reply to this post by Carl Franks

On 30 Jan 2009, at 08:56, Carl Franks wrote:

> 2009/1/29 Ash Berlin <[hidden email]>:
>>
>> On 29 Jan 2009, at 22:03, Carl Franks wrote:
>>
>>> Is it okay to use $result_source->column_info('name')-
>>> >{_inflate_info}
>>> to test whether a column is inflatable / deflatable?
>>> It seems a bit too reliant on internals, to me.
>>>
>>> Or should there be a has_inflatable_column('name') method?
>>>
>>> (and is that what it should be called? do we really also need a
>>> 'has_deflatable_column' too?)
>>>
>>> If someone makes a call, I'll write up a patch for it.
>>>
>>> Carl
>>>
>>
>> There doesn't seem to be a public way to determine this, and indeed
>> accessing anything starting with an _ indicates badness.
>>
>> First things first - what exactly do you care if a column is  
>> inflated or
>> not?
>
> In HTML-FormFu-Model-DBIC, I can't just use get/set_column(),
> otherwise in/deflators won't get called.
> So I've had to document that people can't name fields after DBIC
> built-in methods such as 'delete', otherwise when we call $row->$name
> it'll trash your db.
>
> What I'd like to do is allow the use of any name, by doing something  
> like this:
>
>    $value = $row->result_source->has_inflated_column
>        ? $row->get_inflated_column( $name )
>        : $row->get_column( $name );
>
>    $row->result_source->has_inflated_column
>        ? $row->set_inflated_column( $name, $value )
>        : $row->set_column( $name, $value );
>
> I can't just use get/set_inflated_column() for everything, as it
> croaks if there's no in/deflator for a column.


And why can't you just do $row->$name() or $row->$name($value) ? (I'm  
sure there's a reason, I'm just curious as to what it is.)

>
>
>> Secondly, do you treat relationships as inflated or not?
>
> 'fraid I'm not really sure what that means.
> I generally just use something like
>    @rows = $row->$rel;


Well relationships are kind of like inflate columns in that they are  
likely to have an integer as the raw value, but get turned into an  
object or several.

-ash

_______________________________________________
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/dbix-class@...
Carl Franks

Re: how to determine column is inflatable?

Reply Threaded More More options
Print post
Permalink
2009/1/30 Ash Berlin <[hidden email]>:

>
> On 30 Jan 2009, at 08:56, Carl Franks wrote:
>
>> 2009/1/29 Ash Berlin <[hidden email]>:
>>>
>>> On 29 Jan 2009, at 22:03, Carl Franks wrote:
>>>
>>>> Is it okay to use $result_source->column_info('name')->{_inflate_info}
>>>> to test whether a column is inflatable / deflatable?
>>>> It seems a bit too reliant on internals, to me.
>>>>
>>>> Or should there be a has_inflatable_column('name') method?
>>>>
>>>> (and is that what it should be called? do we really also need a
>>>> 'has_deflatable_column' too?)
>>>>
>>>> If someone makes a call, I'll write up a patch for it.
>>>>
>>>> Carl
>>>>
>>>
>>> There doesn't seem to be a public way to determine this, and indeed
>>> accessing anything starting with an _ indicates badness.
>>>
>>> First things first - what exactly do you care if a column is inflated or
>>> not?
>>
>> In HTML-FormFu-Model-DBIC, I can't just use get/set_column(),
>> otherwise in/deflators won't get called.
>> So I've had to document that people can't name fields after DBIC
>> built-in methods such as 'delete', otherwise when we call $row->$name
>> it'll trash your db.
>>
>> What I'd like to do is allow the use of any name, by doing something like
>> this:
>>
>>   $value = $row->result_source->has_inflated_column
>>       ? $row->get_inflated_column( $name )
>>       : $row->get_column( $name );
>>
>>   $row->result_source->has_inflated_column
>>       ? $row->set_inflated_column( $name, $value )
>>       : $row->set_column( $name, $value );
>>
>> I can't just use get/set_inflated_column() for everything, as it
>> croaks if there's no in/deflator for a column.
>
>
> And why can't you just do $row->$name() or $row->$name($value) ? (I'm sure
> there's a reason, I'm just curious as to what it is.)

If the column name clashes with a DBIC method, such as 'delete', we've
got a problem.

Carl

_______________________________________________
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/dbix-class@...
Felix Antonius Wilhelm Ostmann

Re: how to determine column is inflatable?

Reply Threaded More More options
Print post
Permalink
Carl Franks schrieb:

> 2009/1/30 Ash Berlin <[hidden email]>:
>  
>> On 30 Jan 2009, at 08:56, Carl Franks wrote:
>>
>>    
>>> 2009/1/29 Ash Berlin <[hidden email]>:
>>>      
>>>> On 29 Jan 2009, at 22:03, Carl Franks wrote:
>>>>
>>>>        
>>>>> Is it okay to use $result_source->column_info('name')->{_inflate_info}
>>>>> to test whether a column is inflatable / deflatable?
>>>>> It seems a bit too reliant on internals, to me.
>>>>>
>>>>> Or should there be a has_inflatable_column('name') method?
>>>>>
>>>>> (and is that what it should be called? do we really also need a
>>>>> 'has_deflatable_column' too?)
>>>>>
>>>>> If someone makes a call, I'll write up a patch for it.
>>>>>
>>>>> Carl
>>>>>
>>>>>          
>>>> There doesn't seem to be a public way to determine this, and indeed
>>>> accessing anything starting with an _ indicates badness.
>>>>
>>>> First things first - what exactly do you care if a column is inflated or
>>>> not?
>>>>        
>>> In HTML-FormFu-Model-DBIC, I can't just use get/set_column(),
>>> otherwise in/deflators won't get called.
>>> So I've had to document that people can't name fields after DBIC
>>> built-in methods such as 'delete', otherwise when we call $row->$name
>>> it'll trash your db.
>>>
>>> What I'd like to do is allow the use of any name, by doing something like
>>> this:
>>>
>>>   $value = $row->result_source->has_inflated_column
>>>       ? $row->get_inflated_column( $name )
>>>       : $row->get_column( $name );
>>>
>>>   $row->result_source->has_inflated_column
>>>       ? $row->set_inflated_column( $name, $value )
>>>       : $row->set_column( $name, $value );
>>>
>>> I can't just use get/set_inflated_column() for everything, as it
>>> croaks if there's no in/deflator for a column.
>>>      

set_inflated_columns

  my $copy = $orig->set_inflated_columns({ $col => $val, $rel => $obj,
... });

Sets more than one column value at once, taking care to respect
inflations and relationships if relevant.


i used it and that dont croak :)



>> And why can't you just do $row->$name() or $row->$name($value) ? (I'm sure
>> there's a reason, I'm just curious as to what it is.)
>>    
>
> If the column name clashes with a DBIC method, such as 'delete', we've
> got a problem.
>
> Carl
>
> _______________________________________________
> 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/dbix-class@...
>
>
>  


--
Mit freundlichen Grüßen

Felix Antonius Wilhelm Ostmann
--------------------------------------------------
Websuche   Search   Technology   GmbH   &   Co. KG
Martinistraße 3  -  D-49080  Osnabrück  -  Germany
Tel.:   +49 541 40666-0 - Fax:    +49 541 40666-22
Email: [hidden email] - Website: www.websuche.de
--------------------------------------------------
AG Osnabrück - HRA 200252 - Ust-Ident: DE814737310
Komplementärin:     Websuche   Search   Technology
Verwaltungs GmbH   -  AG Osnabrück  -   HRB 200359
Geschäftsführer:  Diplom Kaufmann Martin Steinkamp
--------------------------------------------------


_______________________________________________
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/dbix-class@...
Carl Franks

Re: how to determine column is inflatable?

Reply Threaded More More options
Print post
Permalink
In reply to this post by Carl Franks
2009/1/29 Carl Franks <[hidden email]>:

> Is it okay to use $result_source->column_info('name')->{_inflate_info}
> to test whether a column is inflatable / deflatable?
> It seems a bit too reliant on internals, to me.
>
> Or should there be a has_inflatable_column('name') method?
>
> (and is that what it should be called? do we really also need a
> 'has_deflatable_column' too?)
>
> If someone makes a call, I'll write up a patch for it.
Attached is a patch against 0.08/trunk -r6358

set_inflatable_column() already had code to explicitly support calling
it on non-inflatable columns.
This patch adds tests for that.

It also changes get_inflatable_column() to also support being called
on non-inflatable columns, plus tests.

Carl


_______________________________________________
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/dbix-class@...

get_inflated_column.patch (2K) Download Attachment
Carl Franks

Fwd: how to determine column is inflatable?

Reply Threaded More More options
Print post
Permalink
Hi,

This seems to have been warnocked, could someone point out if there's
anything I could do to help get it committed?

Since I originally sent this, the inflation test files have been moved
around, so the patch won't apply cleanly - is it worth me sending a
new patch against trunk?

Cheers,
Carl



---------- Forwarded message ----------
From: Carl Franks <[hidden email]>
Date: 2009/5/21
Subject: Re: how to determine column is inflatable?
To: dbix-class mailing list <[hidden email]>


2009/1/29 Carl Franks <[hidden email]>:

> Is it okay to use $result_source->column_info('name')->{_inflate_info}
> to test whether a column is inflatable / deflatable?
> It seems a bit too reliant on internals, to me.
>
> Or should there be a has_inflatable_column('name') method?
>
> (and is that what it should be called? do we really also need a
> 'has_deflatable_column' too?)
>
> If someone makes a call, I'll write up a patch for it.
Attached is a patch against 0.08/trunk -r6358

set_inflatable_column() already had code to explicitly support calling
it on non-inflatable columns.
This patch adds tests for that.

It also changes get_inflatable_column() to also support being called
on non-inflatable columns, plus tests.

Carl


_______________________________________________
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/dbix-class@...

get_inflated_column.patch (2K) Download Attachment