RE: [Catalyst] subclassing model classes

2009-12-16 Thread matthew couchman (JIC)
Hi Wallace,

Thanks for your reply. I'm using the perl debugger:

Class::C3::Componentised::ensure_class_loaded(/home/couchman/catalyst/AntSpec/script/../lib/AntSpec/Schema/Result/Placemark.pm:10):
10: __PACKAGE__-resultset_class('AntSpec::Schema::ResultSet::Placemark');
  DB1 n   
Class::C3::Componentised::ensure_class_loaded(/home/couchman/catalyst/AntSpec/script/../lib/AntSpec/Schema/Result/Placemark.pm:12):
12: 1;
  DB1 x __PACKAGE__   
0  'AntSpec::Schema::Result::Placemark'
  DB2 x __PACKAGE__-resultset_class  
0  'AntSpec::Schema::ResultSet::Placemark'
  DB3 c   
Class::C3::Componentised::ensure_class_loaded(/home/couchman/catalyst/AntSpec/script/../lib/AntSpec/Schema/Result/Vertex.pm:10):
10: __PACKAGE__-resultset_class('AntSpec::Schema::ResultSet::Vertex');
  DB3 n   
Class::C3::Componentised::ensure_class_loaded(/home/couchman/catalyst/AntSpec/script/../lib/AntSpec/Schema/Result/Vertex.pm:12):
12: 1;
  DB3 x __PACKAGE__   
0  'AntSpec::Schema::Result::Vertex'
  DB4 x __PACKAGE__-resultset_class  
0  'AntSpec::Schema::ResultSet::Vertex'
  DB5 x AntSpec::Schema::Result::Placemark-resultset_class   
0  'AntSpec::Schema::ResultSet::Vertex'
  DB6 x AntSpec::Schema::Result::Point-resultset_class   
0  'AntSpec::Schema::ResultSet::Vertex'


Thanks again,

Matt.



 -Original Message-
 From: Wallace Reis [mailto:wall...@reis.org.br]
 Sent: 15 December 2009 23:13
 To: The elegant MVC web framework
 Subject: Re: [Catalyst] subclassing model classes
 
 On 15/12/2009, at 14:58, matthew couchman (JIC) wrote:
  I now have a couple of subclasses of Point called Vertex and
 Placemark. I'm trying to associate them with my new ResultSet
 subclasses.
 
  In MyApp::Schema::Result::Vertex:
 
  use base 'MyApp::Schema::Result::Point';
  __PACKAGE__-resultset_class('MyApp::Schema::ResultSet::Vertex');
 
 
  And in MyApp::Schema::Result::Placemark:
 
  use base 'MyApp::Schema::Result::Point';
  __PACKAGE__-resultset_class('MyApp::Schema::ResultSet::Placemark');
 
 
  I think __PACKAGE__-resultset_class is calling the parent class
 MyApp::Schema::Result::Point-resultset_class in both cases so the
 second call overwrites the first. How do I avoid this?
 
 
 How are you identifying this behaviour? It shouldn't be like that.
 What does print $schema-source($_)-resultset_class for qw(Vertex
 Placemark) output?
 
 --
wallace reis/wreis Catalyst and DBIx::Class consultancy with
 a clue
Software Engineer  and a commit bit:
 http://shadowcat.co.uk/catalyst/
 Shadowcat Systems Limited
 http://www.shadowcat.co.uk http://www.linkedin.com/in/wallacereis
 ___
 List: Catalyst@lists.scsys.co.uk
 Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
 Searchable archive: http://www.mail-
 archive.com/catalyst@lists.scsys.co.uk/
 Dev site: http://dev.catalyst.perl.org/

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


RE: [Catalyst] subclassing model classes

2009-12-16 Thread Alexander Hartmaier
DBIx::Class::Helper::SubClass fixes the relationships too!
I've spoken about the problem that rels stop working when subclassing a
result class in the irc channel but at that time there wasn't a solution
for it.

Thanks for the hint, I will try it out soon!

--
Best regards, Alex


Am Mittwoch, den 16.12.2009, 13:42 +0100 schrieb matthew couchman (JIC):
 I've just discovered DBIx::Class::Helper::SubClass which seems to have done 
 the trick. Thanks again for all your help.

  -Original Message-
  From: matthew couchman (JIC) [mailto:matthew.couch...@bbsrc.ac.uk]
  Sent: 16 December 2009 10:54
  To: The elegant MVC web framework
  Subject: RE: [Catalyst] subclassing model classes
 
  Hi Wallace,
 
  Thanks for your reply. I'm using the perl debugger:
 
  Class::C3::Componentised::ensure_class_loaded(/home/couchman/catalyst/A
  ntSpec/script/../lib/AntSpec/Schema/Result/Placemark.pm:10):
  10: __PACKAGE__-
  resultset_class('AntSpec::Schema::ResultSet::Placemark');
DB1 n
  Class::C3::Componentised::ensure_class_loaded(/home/couchman/catalyst/A
  ntSpec/script/../lib/AntSpec/Schema/Result/Placemark.pm:12):
  12: 1;
DB1 x __PACKAGE__
  0  'AntSpec::Schema::Result::Placemark'
DB2 x __PACKAGE__-resultset_class
  0  'AntSpec::Schema::ResultSet::Placemark'
DB3 c
  Class::C3::Componentised::ensure_class_loaded(/home/couchman/catalyst/A
  ntSpec/script/../lib/AntSpec/Schema/Result/Vertex.pm:10):
  10: __PACKAGE__-
  resultset_class('AntSpec::Schema::ResultSet::Vertex');
DB3 n
  Class::C3::Componentised::ensure_class_loaded(/home/couchman/catalyst/A
  ntSpec/script/../lib/AntSpec/Schema/Result/Vertex.pm:12):
  12: 1;
DB3 x __PACKAGE__
  0  'AntSpec::Schema::Result::Vertex'
DB4 x __PACKAGE__-resultset_class
  0  'AntSpec::Schema::ResultSet::Vertex'
DB5 x AntSpec::Schema::Result::Placemark-resultset_class
  0  'AntSpec::Schema::ResultSet::Vertex'
DB6 x AntSpec::Schema::Result::Point-resultset_class
  0  'AntSpec::Schema::ResultSet::Vertex'
 
 
  Thanks again,
 
  Matt.
 
 
 
   -Original Message-
   From: Wallace Reis [mailto:wall...@reis.org.br]
   Sent: 15 December 2009 23:13
   To: The elegant MVC web framework
   Subject: Re: [Catalyst] subclassing model classes
  
   On 15/12/2009, at 14:58, matthew couchman (JIC) wrote:
I now have a couple of subclasses of Point called Vertex and
   Placemark. I'm trying to associate them with my new ResultSet
   subclasses.
   
In MyApp::Schema::Result::Vertex:
   
use base 'MyApp::Schema::Result::Point';
__PACKAGE__-resultset_class('MyApp::Schema::ResultSet::Vertex');
   
   
And in MyApp::Schema::Result::Placemark:
   
use base 'MyApp::Schema::Result::Point';
__PACKAGE__-
  resultset_class('MyApp::Schema::ResultSet::Placemark');
   
   
I think __PACKAGE__-resultset_class is calling the parent class
   MyApp::Schema::Result::Point-resultset_class in both cases so the
   second call overwrites the first. How do I avoid this?
  
  
   How are you identifying this behaviour? It shouldn't be like that.
   What does print $schema-source($_)-resultset_class for qw(Vertex
   Placemark) output?
  
   --
  wallace reis/wreis Catalyst and DBIx::Class consultancy
  with
   a clue
  Software Engineer  and a commit bit:
   http://shadowcat.co.uk/catalyst/
   Shadowcat Systems Limited
   http://www.shadowcat.co.uk http://www.linkedin.com/in/wallacereis
   ___
   List: Catalyst@lists.scsys.co.uk
   Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
   Searchable archive: http://www.mail-
   archive.com/catalyst@lists.scsys.co.uk/
   Dev site: http://dev.catalyst.perl.org/
 
  ___
  List: Catalyst@lists.scsys.co.uk
  Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
  Searchable archive: http://www.mail-
  archive.com/catalyst@lists.scsys.co.uk/
  Dev site: http://dev.catalyst.perl.org/

 ___
 List: Catalyst@lists.scsys.co.uk
 Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
 Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
 Dev site: http://dev.catalyst.perl.org/


***
T-Systems Austria GesmbH   Rennweg 97-99, 1030 Wien
Handelsgericht Wien, FN 79340b
***
Notice: This e-mail contains information that is confidential and may be 
privileged.
If you are not the intended recipient, please notify the sender and then
delete this e-mail immediately.
***

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] subclassing model classes

2009-12-15 Thread Alexander Hartmaier
Hi Matt!

You might want to take a look at
DBIx::Class::Schema::RestrictWithObject.

Normally I add a method to the ResultSet class of that Result class:

in ResultSet::Device:

=item search_active

Returns a resultset with all active devices.

=cut

sub search_active {
my $self = shift;

return $self-search_rs({
'me.fk_monitor' = { '!=' = 3 },
});
}

In Result::Device:

__PACKAGE__-resultset_class('NAC::Model::DBIC::ResultSet::Device');

--
Best regards, Alex


Am Dienstag, den 15.12.2009, 12:32 +0100 schrieb matthew couchman (JIC):
 Hi,



 I’m trying to subclass a model class so that when I search it only
 pulls out rows of a certain type. I thought that perhaps I could
 achieve that by overriding the search() function and adding a
 condition to the list of arguments as below:



 package MyApp::Schema::Result::Vertex;



 use strict;

 use warnings;



 use base 'MyApp::Schema::Result::Point';



 # override search

 sub search {

 my $self = shift;

 my $condition = { type = 'vertex' };

 return $self-next::method($condition, @_);

 }



 1;



 I don’t think that my new search function is ever called though. Do I
 need to override anything else or am I just barking up the wrong tree
 completely?



 Thanks for your help,



 Matt.








***
T-Systems Austria GesmbH   Rennweg 97-99, 1030 Wien
Handelsgericht Wien, FN 79340b
***
Notice: This e-mail contains information that is confidential and may be 
privileged.
If you are not the intended recipient, please notify the sender and then
delete this e-mail immediately.
***

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] subclassing model classes

2009-12-15 Thread Wallace Reis
On 15/12/2009, at 08:32, matthew couchman (JIC) wrote:
 Hi,

Hi!
Are you using DBIx::Class, right? So, note that DBIC is a separate project and 
has its own ML (http://lists.scsys.co.uk/mailman/listinfo/dbix-class/).

 I’m trying to subclass a model class so that when I search it only pulls out 
 rows of a certain type. I thought that perhaps I could achieve that by 
 overriding the search() function and adding a condition to the list of 
 arguments as below:
 I don’t think that my new search function is ever called though. Do I need to 
 override anything else or am I just barking up the wrong tree completely?

You want to extend a resultset class with a custom method like:

package MyApp::Schema::ResultSet::Point;

use base 'DBIx::Class::ResultSet';

sub vertex {
my $rs = shift;
return $rs-search({ type = 'vertex' });
}

1;

--
   wallace reis/wreis Catalyst and DBIx::Class consultancy with a clue
   Software Engineer  and a commit bit: http://shadowcat.co.uk/catalyst/
Shadowcat Systems Limited
http://www.shadowcat.co.uk http://www.linkedin.com/in/wallacereis


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


RE: [Catalyst] subclassing model classes

2009-12-15 Thread matthew couchman (JIC)
Hi Alex,

Thanks for your reply and thanks to Wallace as well as apologies for mailing 
the wrong group. I think I have a clearer idea of how things are working now so 
your help is very much appreciated. I have a follow up question which I hope 
you don't mind me posting here for completeness. 

I now have a couple of subclasses of Point called Vertex and Placemark. I'm 
trying to associate them with my new ResultSet subclasses.

In MyApp::Schema::Result::Vertex:

use base 'MyApp::Schema::Result::Point';
__PACKAGE__-resultset_class('MyApp::Schema::ResultSet::Vertex');


And in MyApp::Schema::Result::Placemark:

use base 'MyApp::Schema::Result::Point';
__PACKAGE__-resultset_class('MyApp::Schema::ResultSet::Placemark');


I think __PACKAGE__-resultset_class is calling the parent class 
MyApp::Schema::Result::Point-resultset_class in both cases so the second call 
overwrites the first. How do I avoid this?

Many thanks again for your help,

Matt.



 -Original Message-
 From: Alexander Hartmaier [mailto:alexander.hartma...@t-systems.at]
 Sent: 15 December 2009 12:56
 To: The elegant MVC web framework
 Subject: Re: [Catalyst] subclassing model classes
 
 Hi Matt!
 
 You might want to take a look at
 DBIx::Class::Schema::RestrictWithObject.
 
 Normally I add a method to the ResultSet class of that Result class:
 
 in ResultSet::Device:
 
 =item search_active
 
 Returns a resultset with all active devices.
 
 =cut
 
 sub search_active {
 my $self = shift;
 
 return $self-search_rs({
 'me.fk_monitor' = { '!=' = 3 },
 });
 }
 
 In Result::Device:
 
 __PACKAGE__-resultset_class('NAC::Model::DBIC::ResultSet::Device');
 
 --
 Best regards, Alex
 
 
 Am Dienstag, den 15.12.2009, 12:32 +0100 schrieb matthew couchman
 (JIC):
  Hi,
 
 
 
  I’m trying to subclass a model class so that when I search it only
  pulls out rows of a certain type. I thought that perhaps I could
  achieve that by overriding the search() function and adding a
  condition to the list of arguments as below:
 
 
 
  package MyApp::Schema::Result::Vertex;
 
 
 
  use strict;
 
  use warnings;
 
 
 
  use base 'MyApp::Schema::Result::Point';
 
 
 
  # override search
 
  sub search {
 
  my $self = shift;
 
  my $condition = { type = 'vertex' };
 
  return $self-next::method($condition, @_);
 
  }
 
 
 
  1;
 
 
 
  I don’t think that my new search function is ever called though. Do I
  need to override anything else or am I just barking up the wrong tree
  completely?
 
 
 
  Thanks for your help,
 
 
 
  Matt.
 
 
 
 
 
 
 
 
 
 ***
 T-Systems Austria GesmbH   Rennweg 97-99, 1030 Wien
 Handelsgericht Wien, FN 79340b
 
 ***
 Notice: This e-mail contains information that is confidential and may
 be privileged.
 If you are not the intended recipient, please notify the sender and
 then
 delete this e-mail immediately.
 
 ***
 
 ___
 List: Catalyst@lists.scsys.co.uk
 Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
 Searchable archive: http://www.mail-
 archive.com/catalyst@lists.scsys.co.uk/
 Dev site: http://dev.catalyst.perl.org/
___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/