Development

#7709 ([PATCH] [sfPropelPlugin] Make better use of autogenerated __toString methods in i18n tables)

You must first sign up to be able to contribute.

Ticket #7709 (closed enhancement: fixed)

Opened 4 years ago

Last modified 4 years ago

[PATCH] [sfPropelPlugin] Make better use of autogenerated __toString methods in i18n tables

Reported by: Crafty_Shadow Assigned to: Kris.Wallsmith
Priority: minor Milestone: 1.3.0
Component: sfPropelPlugin Version: 1.3.x DEV
Keywords: sfPropelPlugin, Propel1.4, I18N Cc:
Qualification: Accepted

Description

As the Propel 1.4 What's new page notes, Propel now can generate automatically a toString() method based on the schema. Example for symfony:

  static_page:
    id:             ~
    slug:           { phpName: Slug, type: VARCHAR, size: '255', required: true }
    title:          { phpName: Title, type: VARCHAR, size: '150', required: true, primaryString: true } 

This generates:

	/**
	 * Return the string representation of this object
	 *
	 * @return string The value of the 'title' column
	 */
  public function __toString()
  {
    return (string) $this->getTitle();
  }

Which is all good, but couldn't symfony be one step smarter and transfer this toString method to parent i18n tables like so:

  static_page:
    id:             ~
    slug:           { phpName: Slug, type: VARCHAR, size: '255', required: true }
  static_page_i18n:
    title:          { phpName: Title, type: VARCHAR, size: '150', required: true, primaryString: true }
    content:        { phpName: Content, type: LONGVARCHAR, required: true }
echo $static_page;
Output: the value of the TITLE column of the static_page_i18n table

Attachments

7709_1.patch (1.7 kB) - added by Crafty_Shadow on 11/29/09 16:17:44.

Change History

11/28/09 15:03:01 changed by FabianLange

Can you come up with a patch? would it mean to generate a toString that invokes the i18n table toString ?

11/28/09 15:13:40 changed by Crafty_Shadow

There are a few ways of realizing this, but I was thinking something along the lines of: Check for primaryString property for one of the fields of the main table, if there is none check the i18n table. If there is a one, create a proxy not dissimilar to the proxy methods for retrieving column values of the i18n table (with culture set to null, ie auto-detect). Or, as you said, simply call toString() on the related object, though it seems kind of a butch approach :)

I can write a patch by tomorrow evening.

11/29/09 16:17:44 changed by Crafty_Shadow

  • attachment 7709_1.patch added.

11/29/09 16:22:59 changed by Crafty_Shadow

  • qualification changed from Unreviewed to Ready for core team.

I can't attach tests for this patch because testing propel is a bit of a handful, however I did test it manually and there seemed to be no problems. The patch includes phpdoc. In essence, it checks for a primaryString enabled column on the main table, then checks the related i18n table, and if there is one it creates a toString method which is identical to the proxy methods for the i18n table columns (with the exception that toString cannot take arguments, so the culture is hard set to null, ie auto-select)

11/29/09 16:28:04 changed by Crafty_Shadow

  • summary changed from [sfPropelPlugin] Make better use of autogenerated __toString methods in i18n tables to [PATCH] [sfPropelPlugin] Make better use of autogenerated __toString methods in i18n tables.

11/30/09 13:02:52 changed by Crafty_Shadow

Will this be making it into tomorrow's release? It is a pretty straight-forward patch.

11/30/09 20:10:49 changed by Kris.Wallsmith

  • owner changed from fabien to Kris.Wallsmith.
  • status changed from new to assigned.
  • qualification changed from Ready for core team to Accepted.

11/30/09 20:53:50 changed by Kris.Wallsmith

  • status changed from assigned to closed.
  • resolution set to fixed.

(In [24597]) [1.3, 1.4] fixed casting of propel i18n objects to string (closes #7709)