Joining an undeclared table in Propel or Join Custom Table Propel / ~#root -i Joining an undeclared table in Propel or Join Custom Table Propel / ~#root -i Joining an undeclared table in Propel or Join Custom Table Propel / ~#root -i Joining an undeclared table in Propel or Join Custom Table Propel / ~#root -i Joining an undeclared table in Propel or Join Custom Table Propel / ~#root -i Joining an undeclared table in Propel or Join Custom Table Propel / ~#root -i Joining an undeclared table in Propel or Join Custom Table Propel / ~#root -i Joining an undeclared table in Propel or Join Custom Table Propel / ~#root -i
  • RU
  • UA
  • EN
  • Create an online store
  • Documentation
  • Blog
    • Unix ОS
    • Php
    • MySQL
    • JavaScript
    • Package Managers
    • Docker
    • Seo
  • Auxiliary services
    • Short Links
    • Exchange views YouTube
  • Sign in
  • Create Account
  • Home
  • Php
  • Joining an undeclared table in Propel or Join Custom Table Propel

Joining an undeclared table in Propel or Join Custom Table Propel

The other day, I faced the task of sorting the output of products according to a table that is not described in schema.xml. I will give a brief example of the table schema and table structure with positions, by which I should have sorted the products.

Simplified product table (merged the translation table with the main one and truncated the fields):

id (int) product id
name (string) Name
create_date (int) the date

Schema of this table (schema.xml):

<table name="shop_products" phpName="SProducts">
<vendor type="mysql">
<parameter name="Charset" value="utf8"/>
</vendor>

<column name="id" type="INTEGER" required="true" autoIncrement="true" primaryKey="true"/>
<column name="name" type="varchar" size="500" required="true"/>
<column name="create_date" type="INTEGER"/>
</table>

Let's say we have a binding of products to articles, and each article can have the same product and each product can have its own position in each article.

I will give an example of a table of articles and product links (let's call the table link_page):

page_id (int) Article ID (given as an example)
product_id (int) Product ID from the SProducts schema
position (int) The position in which the product is in the article

Here there is a position for each product in the article, but there is no link in the product table to make join a sing-song. So let's start doing this:

SProductsQuery::create()
->addJoin('shop_products.id' , 'link_page.product_id', Criteria::INNER_JOIN)
->addAsColumn('position', 'link_page.position')
->where('page_link_product.page_id = ' . 'ID страницы товара')
->orderBy('position','ASC')
->find();

In my case, the full path to Criteria::INNER_JOIN is \Propel\Runtime\ActiveQuery\Criteria::INNER_JOIN .

SProductsQuery - the generated model according to the scheme, simplified for understanding and described above.

This query will make it possible to connect a table not declared in the models to the query, so as not to make crutches and bicycles for sorting.

Try it, figure it out, in my case, addJoin() allowed me to save the time of rewriting and regenerating the schema for the needs, thereby not burdening the page of the article, which contains products.

21 May 18
730
0

Comments

Name
E-mail
Rating
Review

Other articles from the category

25 April 2022

Create and download CSV in PHP

Consider the possibility of quickly creating a CSV file with automatic file download. Consider the formation, separators and header for the ability to download the file.

19 June 2019

ImageCMS Templates 4.10-4.12.1

Latest templates from ImageCMS 4.12, authorization is required to download.

26 January 2019

Long-term storage of the basket in the online store

Consider options for popular options for storing goods in a shopping cart in an online store. Let's outline the pros and cons of such storage. Consider options for long-term storage of the basket.

17 January 2019

License key for ImageCMS 4.9-4.12.1 Pro and Pre

Creating a key for imageCMS 4.9-4.12.1 Pro and Pre. You must be logged in to receive it.

07 December 2018

$_SERVER[DOCUMENT_ROOT] in CLI or Cron

When running the script from the console, there is no DOCUMENT_ROOT in $_SERVER. Let's try to get around this in our own ways, catch the file directory.

31 October 2018

Analysis of loaded parts of Php code with xhprof

After developing any tool in PHP, the question becomes how resourceful the created code is and what elements it still affects. Let's take a look at xhprof installation, configuration, and how to work with xhprof.

18 July 2018

Grouping conditions in an ORM Propel query (condition, combine)

Let's analyze the possibility of combining conditions in a query by groups in Propel. Consider an example of filtering by fields using ->condition() and ->combine().

14 June 2018

Authorization 1C on the site PHP_AUTH_USER on CentOS apache

Faced the problem of authorization 1s on the site. For some reason, the server did not accept the PHP_AUTH_USER and PHP_AUTH_PW parameters from it. Let's take a closer look at the solution and bypassing these parameters in $_SERVER .

Categories

  • Unix OS
  • Php
  • MySQL
  • JavaScript
  • Package Managers
  • Docker
  • Seo

Latest comments

Добрый день, Сергей. Я на более новых версиях блют...
root-i
23.02.23
Пробовал на transmart колонке. Ничего из перечисле...
Сергей
20.02.23
HenryMit, может быть
root-i
07.02.23
Неофрейдизм — это… Определение, принципы, представ...
HenryMit
07.02.23

I share information in which I needed help and spent a lot of time figuring it out. If the information helped at least one person, then this site was not created in vain.

Thank you for the continuation of the site:
Contacts

Telegram Viber Mail

Search for articles

  • Sign in
  • Create Account

Powered by chmod -R