I use propelorm (propel 1.6) plugin and symfony 1.4.20.
I have book table with I18n, and this book have relation with gallery table which also have I18n. I fill all book form fields, added two gallery images, filled all images fields. Click on save - it seems all ok: book fields are ok, first and second image have been uploaded, but only first image have filled i18n fields, second image all i18n fields are empty. What's the prob ?
(there's no redeclared doSave(), save(), bind() and other form methods)
schema:
book:
id: ~
title: { type: varchar(255), required: true }
author: { type: varchar(255), required: true }
description: { type: longvarchar, required: true }
sortable_rank: { type: integer, required: true }
is_active: { type: boolean, default: 1 }
_indexes:
active_sort: [ is_active, sortable_rank ]
_propel_behaviors:
sortable:
rank_column: sortable_rank
i18n:
i18n_columns: [title, description, author]
locale_column: culture
locale_alias: culture
default_locale: en
book_gallery:
id: ~
book_id: { type: integer, foreignTable: book, foreignReference: id, required: true, onDelete: cascade }
title: { type: varchar(255), required: true }
image: { type: varchar(255), required: true }
_propel_behaviors:
i18n:
i18n_columns: [title]
locale_column: culture
locale_alias: culture
default_locale: en
book form:
$languages = LanguageQuery::create()->getAllAsArray(); // returns like array('en' => 'english', ...);
$this->embedI18n(array_keys($languages));
$this->widgetSchema->setLabels($languages);
$this->embedRelation('BookGallery', array(
'title' => 'Application book store list',
'item_pattern' => 'Application book store %index%',
));
book gallery form:
$languages = LanguageQuery::create()->getAllAsArray(); // same as in book form
$this->embedI18n(array_keys($languages));
$this->widgetSchema->setLabels($languages);
Related
Below is a Contentful migration I wrote to create a content model called 'Trip' in Contentful. What I would like to do is specify the format of the "Start Date" and "End Date" fields. Contentful gives you three formatting options that can be set in the UI:
Date only
Date and time without timezone
Date and time with timezone
Without specifying the format in my migration file, I get format #3 by default and I need format #1. Anyone familiar with how to do this?
Thanks!
class CreateTrip < RevertableMigration
self.content_type_id = 'trip'
def up
with_space do |space|
# Create content model
content_type = space.content_types.create(
name: 'Trip',
id: content_type_id,
description: 'Content model for trip cards'
)
# Set validation
validation_for_country = Contentful::Management::Validation.new
validation_for_country.in = ['Bolivia','Haiti','India','Nicaragua', 'Puerto Rico', 'South Africa']
content_type.fields.create(id: 'image', name: 'Image', type: 'Link', link_type: 'Asset', required: true)
content_type.fields.create(id: 'country', name: 'Country', type: 'Symbol', required: true, validations: [validation_for_country])
content_type.fields.create(id: 'trip_details', name: 'Trip Details', type: 'Symbol')
content_type.fields.create(id: 'start_date', name: 'Start Date', type: 'Date', required: true)
content_type.fields.create(id: 'end_date', name: 'End Date', type: 'Date', required: true)
content_type.fields.create(id: 'trip_description', name: 'Trip Description', type: 'Text')
content_type.fields.create(id: 'link_url', name: 'Link URL', type: 'Symbol', required: true)
# Publish
content_type.save
content_type.publish
# Editor interface config
editor_interface = content_type.editor_interface.default
controls = editor_interface.controls
field = controls.detect { |e| e['fieldId'] == 'trip_details' }
field['settings'] = { 'helpText' => 'City, month, participant type, etc.' }
editor_interface.update(controls: controls)
editor_interface.reload
content_type.save
content_type.publish
end
end
end
When I export my content types using the contentful export command via the Contentful CLI, I can see something similar to this in my JSON:
{
"fieldId": "endDate",
"settings": {
"ampm": "24",
"format": "timeZ",
"helpText": "(Optional) The date and time when the event ends..."
},
"widgetId": "datePicker"
},
{
"fieldId": "internalTitle",
"widgetId": "singleLine"
},
{
"fieldId": "startDate",
"settings": {
"ampm": "24",
"format": "timeZ",
"helpText": "The date/time when this schedule starts..."
},
"widgetId": "datePicker"
}
Now, I don't use the Ruby migration tooling, but this leads me to believe you can set field['widgetId'] = 'datePicker' and
field['settings'] = {
'format' => 'dateonly',
'helpText' => ...
}
Let me know if that helps!
I have a bit of problem for using Sequelize with include. The problem is that my model uses two primary keys in child table.
So it goes like this
Parent table
User : Id, ...
Post : Id, UserId(foreign key, binds to user id), ...
Post Hash Tag : HashTag, PostId(foreign key, binds to Post id), UserId(foreign key, binds to user id of Post table)
So the table hierarchy looks like this
user - post - post hash tag
Now when I try to do like this,
Post.findAll(
include: {
model: post hash tag
}
)
then it only searches the post hash tags for where post id of post hash tag table is equal to post id of post table
So I added like this
Post.findAll(
include: {
model: post hash tag
where: {
col1: models.sequelize.where(models.sequelize.col('POST.USER_ID'), '=', models.sequelize.col('POST_HASH_TAG.USER_ID'))
}
}
);
Then it will gives a problem at 'where' clause that Post.USER_ID cannot be found.
If I change col1 value to Post.userId then now it solves the above error but gives another error at 'on' clause
Do you have any idea how I can solve this?
The full model is given here
User
sequelize.define('User', {
id: { type: DataTypes.STRING(6), field: 'ID', primaryKey : true }
)
Post - I know multiple primary declaration is not working correctly, so don't bother to consider too much
sequelize.define('Post', {
id: { type: DataTypes.STRING(6), field: 'ID', primaryKey: true },
userId: { type: DataTypes.STRING(6), field: 'USER_ID', primaryKey: true }
)
Post hash tag
sequelize.define('PostHashTag', {
postId: { type: DataTypes.STRING(6), field: 'POST_ID', primaryKey: true },
hashTag: { type: DataTypes.STRING(20), field: 'HASH_TAG', primaryKey: true },
userId: { type: DataTypes.STRING(6), field: 'USER_ID', primaryKey: true }
}
)
and the query I used is
Post.findAll({
attributes: ['id', 'userId'],
where: {
userId: userId,
id: { $lt: postId }
},
include: [{
model: models.PostHashTag,
attributes: ['hashTag'],
where: {
col1: models.sequelize.where(models.sequelize.col('Post.USER_ID'), '=', models.sequelize.col('PostHashTag.userId'))
}]).then(...)
I found an answer by myself... col1:
models.sequelize.where(models.sequelize.col('Post.USER_ID'), '=', models.sequelize.col('PostHashTag.userId'))
this should be
userId: models.sequelize.where(models.sequelize.col('POST.userId'), '=', models.sequelize.col('POST_HASH_TAG.USER_ID'))
this will work. The physical names of table and column used in parenthesis
in Jobeet there is this part below of the schema:
jobeet_category:
_attributes: { isI18N: true, i18nTable: jobeet_category_i18n }
id: ~
jobeet_category_i18n:
id: { type: integer, required: true, primaryKey: true, foreignTable: jobeet_category, foreignReference: id }
culture: { isCulture: true, type: varchar, size: 7, required: true, primaryKey: true }
name: { type: varchar(255), required: true }
slug: { type: varchar(255), required: true }
I have created the corresponding modules in the backend, but when i try to create a new "jobeet_category_i18n" i miss the select that would permit choose a "jobeet_category" object.
Anyway i try to create it, but as i expected an error message that speaks about the foreign key is showed.
Is that schema ok? why is not showed the select to choose a "jobeet_category" object?
Javi
http://www.symfony-project.org/forms/1_4/en/08-Internationalisation-and-Localisation#chapter_08_propel_objects_internationalization
i have this schema and fixtures:
sedi:
_attributes: { isI18N: true, i18nTable: sediI18n }
id: ~
sediI18n:
id: { type: integer, required: true, primaryKey: true, foreignTable: sedi, foreignReference: id }
culture: { isCulture: true, type: varchar, size: 7, required: true, primaryKey: true }
paese_indirizzo: { type: varchar(6), required: true }
indirizzo: { type: varchar(1024), required: true }
Sedi:
sede_roma_1: { }
SediI18n:
sede_roma_1_italiano: { id: sede_roma_1, culture: it, paese_indirizzo: eu, indirizzo: "Ufficio di Roma 1 Testaccio Via Galvani, 17 Roma - 00153 Italia" }
sede_roma_1_francese: { id: sede_roma_1, culture: fr, paese_indirizzo: eu, indirizzo: "Rome Office 1: Testaccio Via Galvani, 17 Roma - 00153 Italia" }
I'm trying to show in a template only the sede in Italian language ("Ufficio di Roma") but it shows also the sede in French language..
In that template I have write var_dump($sf_user->getCulture()) and prints "it".
Any idea?
I suggest you stay with the conventions and use lowercase characters and underscores for the table names. In fact, you don't have to write much code to get I18N support. What should be enough:
sedi:
id:
sedi_i18n:
paese_indirizzo: { type: varchar(6), required: true }
indirizzo: { type: varchar(1024), required: true }
Adapt your fixtures accordingly.
I have a database design case which I am curios whether Doctrine ORM supports it out-of-box.
Product:
columns:
id: {type: integer, primary: true, autoincrement: true }
type_id: { type: integer, notnull: true }
brand_id: { type: integer, notnull: true }
relations:
ProductType:
class: ProductType
local: type_id
foreign: id
Brand:
class: Brand
local: brand_id
foreign: id
ProductType:
actAs:
I18n:
fields: { name }
columns:
id: {type: integer, primary: true, autoincrement: true }
name: { type: string(255), notnull: true }
Brand:
actAs:
I18n:
fields: { name }
columns:
id: {type: integer, primary: true, autoincrement: true }
name: { type: string(255), notnull: true }
I want to slugify Products table, ie. products will be reached via their slugs. However, as you see both brand and productype tables has i18n behaviour. And moreover, product doesnt have a name. A product's slug will be: "Brand.name - ProductType.name", and vary with the language served.
For this scenario, is there anyway I can use Sluggable behaviour of Doctrine to sluggify my products automatically. Or do I have to manage it manually?
By the way my environment configuration is:
Doctrine Version: 1.2
Symfony: 1.4.1
Thanks
My understanding is that you need to have the slug in both Product Type and Brand models. You can leave the Product definition as it is. Anyway, I'm assuming from your question that there is only one product for every brand+type (even if it doesn't have to much sense). So ProductType and Brand will be defined like this:
schema.yml
----------
ProductType:
actAs:
I18n:
fields: { name }
actAs:
Sluggable: { fields: [name], uniqueBy: [lang], canUpdate: true }
columns:
...
Then you have to configure your Product route to use the slugs. And after that you will need to configure the action to check what you are getting from the route.
For example, this could be your route for Products:
routing.yml
-----------
product:
url: /:sf_culture/product/:brand_slug/:type_slug
param: { module: product, action: view }
requirements:
sf_culture: (?:en|fr)
sf_method: get
Then in the action you will call to your own findOneBySlugs($brand_slug, $type_slug) method:
product/actions/actions.class.php
---------------------------------
public function executeView(sfWebRequest $request)
{
$product = Doctrine::getTable('Product')
->findOneBySlugs(
$request->getParameter('brand_slug'),
$request->getParameter('type_slug')
);
$this->forward404Unless($product);
}
the problem with that solution are the queries. With:
$product = Doctrine::getTable('Product')
->findOneBySlugs(
$request->getParameter('brand_slug'),
$request->getParameter('type_slug')
);
you are doing a 5-join query if I'm not mistaken. You can improve to do only three (product, brand_translation and producttype_translation)
I'm in a similar situation, and the best option is to create a slug for each product using the brand or product type name in this case. So you would only need:
$product = Doctrine::getTable('Product')
->findOneBySlug($request->getParameter('slug'));
I'm thinking between two options:
Product:
actAs:
Sluggable:
unique: true
fields: [title]
builder: [Slug, slugify]
or using the getUniqueSlug() function on the record class. I think the first option is best so you don't have to worry about uniqueness.