Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

SitePoint PHP Blog:
Re-Introducing Eloquent’s Polymorphic Relationships
Jul 17, 2017 @ 17:55:20

On the SitePoint PHP blog they've posted a tutorial from Christopher Vundi that looks at the relationships that are a part of the Eloquent database package in Laravel. He uses the article to re-introduce polymorphic relationships you can define between your models to make cross-entity data access easier.

You’ve probably used different types of relationships between models or database tables, like those commonly seen in Laravel: one-to-one, one-to-many, many-to-many, and has-many-through. But there’s another type of relationship that’s not so common: polymorphic. So what is a polymorphic relationship?

A polymorphic relationship is where a model can belong to more than one other model on a single association. [...] With polymorphic relationships, we don’t need two tables. Let’s look into polymorphic relationships through a practical example.

He then starts in on what he'll be making in the tutorial, a system to manage songs, albums and upvotes. He outlines the basic table structure and uses the artisan command to generate both the models and migrations for the three tables. He then runs the migration to build out the tables and starts filling in the relation methods (hasOne, belongsTo, etc) and the special "morph*" methods to define the polymorphic relationships. He includes code examples showing how to access the information from the model objects and how to create custom polymorphic types if needed.

tagged: laravel eloquent relationships tutorial introduction polymorphic

Link: https://www.sitepoint.com/eloquents-polymorphic-relationships-explained/

Bradley Holt:
Entity Relationships in a Document Database at ZendCon 2012 (Video & Slides)
Nov 19, 2012 @ 16:03:55

If you weren't able to attend this year's ZendCon conference and wanted to see Bradley Holt's talk about entity relationships and document databases, you're in luck - he's posted both the video and slides to his site. Here's his summary of the session:

Unlike relational databases, document databases like CouchDB and MongoDB do not directly support entity relationships. This talk will explore patterns of modeling one-to-many and many-to-many entity relationships in a document database. These patterns include using an embedded JSON array, relating documents using identifiers, using a list of keys, and using relationship documents. This talk will explore how these entity relationship patterns equate to how entities are joined in a relational database. We'll take a look at the relevant differences between document databases and relational databases. For example, document databases do not have tables, each document can have its own schema, there is no built-in concept of relationships between documents, views/indexes are queried directly instead of being used to optimize more generalized queries, a column within a result set can contain a mix of logical data types, and there is typically no support for transactions across document boundaries.

He also includes links to two of the tools he mentions in the talk - Doctrine CouchDB and the Doctrine MongoDB ORM.

tagged: zendcon12 entity relationships document database video slides

Link:

Giorgio Sironi's Blog:
Doctrine 2 now has lazy loading
Aug 07, 2009 @ 16:07:37

As is mentioned in this new post to Giorgio Sironi's blog, the latest version of Doctrine now includes lazy loading functionality.

Lazy loading is the capability of performing a expensive operation on demand, only when it reveals necessary from a client request. [...] In Doctrine 2 I made some architectural choices implementing the proxy approach, which substitute a subclassing object to every association which is not eager-loaded.

There's two main places you can see these differences - in the one/many to one associations dynamic proxies and collection interface.

tagged: doctrine lazy load relationships

Link:

PHP-GTK Community Site:
Building a submenu in a GtkMenubar
Dec 06, 2006 @ 14:55:00

The PHP-GTK Community site is back again today with another quick tutorial showing how to build a submenu with the help of the GtkMenubar widget.

It's broken us into the key sections - details, a visual tree of the structure, the logic tree and relationships, and, finally the source code. It's a pretty simple process of creating the menu and appending the elements onto it, much like a normal drop down menu. The key is in the set_submenu function, creating a new object for the code to append the submenu elements to. The rest is just simple appends.

They've also included a screenshot to illustrate the end result.

tagged: submenu gtkmenubar tutorial visual tree logical relationships submenu gtkmenubar tutorial visual tree logical relationships

Link:

PHP-GTK Community Site:
Building a submenu in a GtkMenubar
Dec 06, 2006 @ 14:55:00

The PHP-GTK Community site is back again today with another quick tutorial showing how to build a submenu with the help of the GtkMenubar widget.

It's broken us into the key sections - details, a visual tree of the structure, the logic tree and relationships, and, finally the source code. It's a pretty simple process of creating the menu and appending the elements onto it, much like a normal drop down menu. The key is in the set_submenu function, creating a new object for the code to append the submenu elements to. The rest is just simple appends.

They've also included a screenshot to illustrate the end result.

tagged: submenu gtkmenubar tutorial visual tree logical relationships submenu gtkmenubar tutorial visual tree logical relationships

Link:

Nefarious Designs:
Object-Oriented PHP Part 3: Taking Relationships Further
Aug 23, 2006 @ 11:33:31

Nefarious Designs has posted the next part of their "Object-Oriented PHP" series today, the third part looking at how to take the relationships (discussed in part two) even further.

In "Part 1: Definition" we took a look at defining objects and classes in PHP. In "Part 2: Relationships" we looked at linking our objects and classes together. In part 3 I'm going to add to those relationships by looking at visibility, polymorphism and the scope resolution operator.

He starts off with a look at access modifiers (private, public, protected) on both attributes and methods. Next is a look at polymorphism with an example of using a getHTML function in both a base formElement class and the child class of textarea. He then talks about the scope resolution operator (::) and its use in parent/child relationships and in PHP5's scope.

tagged: part3 object oriented relationships further access polymorphism part3 object oriented relationships further access polymorphism

Link:

Nefarious Designs:
Object-Oriented PHP Part 3: Taking Relationships Further
Aug 23, 2006 @ 11:33:31

Nefarious Designs has posted the next part of their "Object-Oriented PHP" series today, the third part looking at how to take the relationships (discussed in part two) even further.

In "Part 1: Definition" we took a look at defining objects and classes in PHP. In "Part 2: Relationships" we looked at linking our objects and classes together. In part 3 I'm going to add to those relationships by looking at visibility, polymorphism and the scope resolution operator.

He starts off with a look at access modifiers (private, public, protected) on both attributes and methods. Next is a look at polymorphism with an example of using a getHTML function in both a base formElement class and the child class of textarea. He then talks about the scope resolution operator (::) and its use in parent/child relationships and in PHP5's scope.

tagged: part3 object oriented relationships further access polymorphism part3 object oriented relationships further access polymorphism

Link:

Nefarious Designs:
Object-Oriented PHP Part 2: Relationships
Aug 21, 2006 @ 23:06:29

Nefarious Designs has posted part two of their look at the object-oriented functionality, this time, there's a focus on the relationships objects and their friends have.

Following on from my posts "Object-Oriented Concepts" and "Object-Oriented Javascript", I'm going to take a look at OOP in PHP.

In "Part 1: Definition" we took a look at defining objects and classes in PHP. In part 2 I'm going to look at the most important part of any object-oriented system - the relationships.

They look at inheritance, association, aggregation, and references. Code examples are sprinkled liberally to help illustrate the points.

tagged: tutorial part2 object oriented relationships inheritance composition references tutorial part2 object oriented relationships inheritance composition references

Link:

Nefarious Designs:
Object-Oriented PHP Part 2: Relationships
Aug 21, 2006 @ 23:06:29

Nefarious Designs has posted part two of their look at the object-oriented functionality, this time, there's a focus on the relationships objects and their friends have.

Following on from my posts "Object-Oriented Concepts" and "Object-Oriented Javascript", I'm going to take a look at OOP in PHP.

In "Part 1: Definition" we took a look at defining objects and classes in PHP. In part 2 I'm going to look at the most important part of any object-oriented system - the relationships.

They look at inheritance, association, aggregation, and references. Code examples are sprinkled liberally to help illustrate the points.

tagged: tutorial part2 object oriented relationships inheritance composition references tutorial part2 object oriented relationships inheritance composition references

Link:

PHPit.net:
Taking a first look at the AutoCRUD for PHP library
Jun 05, 2006 @ 11:22:29

PHPit.net brings yet another great tutorial your way with this first look at the AutoCRUD library for PHP - a database abstraction layer to help with some of the more mundane tasks (create/read/update/delete) of dealing with your data.

Welcome to this article on the AutoCRUD for PHP library. This library is a new database library specifically for MySQL, written by yours truly. The reason that this library is only compatible with MySQL is that I very rarely need to use another database, and I really wanted to focus on one database. It's possible that the library might get support for other databases in the future, but for now it's strictly MySQL only.

The tutorial provides a quick introduction to the functionality of the library - including built-in support for unique keys, table-object generation on the fly, and the benefit of being fully unit tested. Next up, the setup - there's some sample SQL to plug in to follow with the examples and the starting code to get the class included and working. They look at basic crud functionality, with a highlight on selecting, and the relationship handling abilities built-in.

tagged: autocrud library tutorial part1 sql selecting relationships autocrud library tutorial part1 sql selecting relationships

Link:


Trending Topics: