Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
Gantry::Utils::DBIxClaUser)Contributed Perl DocumenGantry::Utils::DBIxClass(3)

NAME
       Gantry::Utils::DBIxClass	- a DBIx::Class	subclass models	can inherit
       from

SYNOPSIS
	   package YourModel;

	   use base 'Gantry::Utils::DBIxClass';

	   # standard DBIx::Class table	definition

	   __PACKAGE__->sequence_name( 'your_seq' );
	   __PACKAGE__->base_model( 'Your::Schema' );

DESCRIPTION
       By inheriting from this module instead of from DBIx::Class directly,
       you gain	additional helper methods which	various	parts of Gantry	use.

METHODS
       get_listing
	   Parameters: A hash reference	with these keys:

	       schema	- a DBIx::Class::Schema	object
	       order_by	- [optional] a valid SQL ORDER BY clause

	   Returns: an array of	all rows in your table.	 The default order is
	   the foreign_display fields.

       get_form_selections
	   Parameters: A hash reference	with this key:

	       schema -	a DBIx::Class::Schema object

	   Returns: A hash keyed by foreign table name storing an array	of
	   items.  Each	item is	a hash with two	keys like this:

	       {
		   value => $item->$value_method
		   label => $item->foreign_display(),
	       }

	   This	is precisely the format	that all Gantry	CRUD schemes expect in
	   their forms.

	   The value_method is either id (the default) or the result of
	   calling the optional	get_value_method on the	relevant foreign table
	   model class.

       stringify_self
	   This	is an overload callback	used when database row objects are in
	   string context.  The	one here calls id on the row object.  Children
	   should override if their primary key	is not a single	column called
	   'id'.

       create
	   This	method is provided for historical reasons and should no	longer
	   be used, see	gcreate	below.

       In addition to the above	methods, this base class provides the
       following convenience accessors to save typing.	For example, instead
       of typing:

	   my $schema =	$self->get_schema();
	   my @rows   =	$schema->resultset( 'table_name' )->search(
		   { ... },
		   { ... }
	   );

       These methods let you say:

	   my @rows => $TABLE_NAME->gsearch(
		   $self,
		   { ... },
		   { ... }
	   );

       gcreate
       gsearch
       gfind
       gfind_or_create
       gupdate_or_create

       For these methods to work, the invoking controller must use
       Gantry::Plugins::DBIxClassConn.	It handles dbic	connections and
       exports get_schema which	all of the g methods call.

       Alternatively, if you are in a script, you may use other	similar
       methods:

	   my $schema =	AddressBook::Model->connect(
	       $conf->{	dbconn },
	       $conf->{	dbuser },
	       $conf->{	dbpass },
	   );

	   my @rows => $TABLE_NAME->ssearch( $schema, ... );

       These methods expect a valid dbic schema	as their first argument.  The
       available s* methods are:

       screate
       ssearch
       sfind
       sfind_or_create
       supdate_or_create

       Other helper methods:

       datetime_now
	   returns the right SQL command for NOW() (datetime field) depending
	   on whether sqlite or	mysql or pgsql are used.

	   For example in controller to	set the	'modified' column:

	     $params->{modified} = $MY_MODEL->datetime_now($self);

	   where $self is $gantry_site object.

AUTHOR
       Phil Crow <philcrow2000@yahoo.com>

COPYRIGHT and LICENSE
       Copyright (c) 2006, Phil	Crow

       This library is free software; you can redistribute it and/or modify it
       under the same terms as Perl itself, either Perl	version	5.8.6 or, at
       your option, any	later version of Perl 5	you may	have available.

perl v5.32.1			  2021-02-28	   Gantry::Utils::DBIxClass(3)

NAME | SYNOPSIS | DESCRIPTION | METHODS | AUTHOR | COPYRIGHT and LICENSE

Want to link to this manual page? Use this URL:
<https://www.freebsd.org/cgi/man.cgi?query=Gantry::Utils::DBIxClass&sektion=3&manpath=FreeBSD+13.0-RELEASE+and+Ports>

home | help