I have the follwing fixiture file:
Category:
webDev:
name: Development Web
webDesign:
name: Web Desing
Autres:
name: Autres
Post:
Post1:
Category: webDev
title: Ceci est un Test 1
content: TEST
Post2:
Category: webDesign
title: Ceci est un Test 2
content: TEST
Post3:
Category: Autres
title: Ceci est un Test 3
content: TEST
The problem is that webDev is not recognized and the id is not automatically seted.
I don't want to use like that:
Post1:
category_id: 1
title: Ceci est un Test 1
content: TEST
But I want to use the name of the webDev, webDesign or Autres categories names. Is working and I have no error when I run:
./symfony doctrine:build --all --no-confirmation --and-load
However, when I look in MySQL database instead of the category id I get NULL. Why? Where is the error?
Here is my schema.yml
Category:
tableName: categories
columns:
name: string(100)
Post:
tableName: posts
actAs:
Timestampable: ~
Sluggable:
fields: [title]
columns:
category_id: integer
title: string(100)
content: text
relations:
Category:
type: one
foreignType: many
local: id
foreign: id
According to your schema, the foreign key will bet set to post.id instead of post.category_id.
try local: category_id instead of local: id
Related
I'm building a very simple API with maven plugin configuration here. But it generates some Authentication classes (auth package and some other classes like StringUtil, JSON) I've never defined in my configuration. I don't want all these classes, where do they come from ? :
Here is my student.yaml input file :
openapi: 3.0.0
info:
title: student API
description: student demo API by Anthony Errera
version: 1.0.0
paths:
/student:
description: Student Resource
get:
description: operation to fetch student
parameters:
- in: query
name: studentname
required: true
schema:
type: string
responses:
200:
description: Success response
content:
application/json:
schema:
type: array
items:
properties:
StudentID:
type: integer
example: 3
StudentName:
type: string
example: toto
post:
description: add a student
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/student'
responses:
201:
description: student created
components:
schemas:
student:
type: object
properties:
StudentID:
type: integer
example: 3
StudentName:
type: string
example: toto
I have two YAML files with similar formats, however one is running and the other is not running when I run integration tests on my rails app.
Here is the first YAML file which doesn't work:
prince_edward_island:
name: 'prince edward island'
country: 'Canada'
nova_scotia:
name: 'nova scotia'
country: 'Canada'
newfoundland:
name: 'newfoundland'
country: 'Canada'
new_brunswick:
name: 'new brunswick'
country: 'Canada'
quebec:
name: 'quebec'
country: 'Canada'
manitoba:
name: 'manitoba'
country: 'Canada'
alberta:
name: 'alberta'
country: 'Canada'
ontario:
name: 'ontario'
country: 'Canada'
british_columbia: 'Canada'
name: 'british columbia'
country: 'Canada'
saskatchewan: 'Canada'
name: 'saskatchewan'
country: 'Canada'
Here is the second YAML file which does work:
student_advisor_message:
body: 'This is a message'
subject: 'Subject!'
user: student_advisor
manager_message:
body: 'This is a message'
subject: 'Subject!'
user: manager
read_manager_message:
body: 'This is a message'
subject: 'Subject!'
user: manager
agent_manager_message:
body: 'This is a message'
subject: 'Subject!'
user: agent_manager
message_for_jack:
body: 'This is a message'
subject: 'Subject!'
user: manager
message_for_jack_sent:
body: 'This is a sent message'
subject: 'Sent Subject!'
user: manager
message_for_jack_trash:
body: 'This is a trashed message'
subject: 'Trash Subject!'
user: manager
The error is:
ERROR:
while parsing a block mapping
in "<unicode string>", line 1, column 1:
prince_edward_island:
^
expected <block end>, but found '<block mapping start>'
in "<unicode string>", line 34, column 3:
name: 'british columbia'
Can someone explain the difference I am missing between the two? For both I use spaces, not tabs.
There are several errors:
For both I use tabs, not spaces.
Tabs are not allowed as indentation characters in YAML.
country: 'Canada'
nova_scotia:
Here, you give both a scalar ('Canada') and a mapping (starting with nova_scotia:) as value for the key country. There may only be one value for this key. You either have to remove the scalar 'Canada' or move the mapping it contains elsewhere.
british_columbia: 'Canada'
name: 'british columbia'
country: 'Canada'
saskatchewan: 'Canada'
name: 'saskatchewan'
country: 'Canada'
Here, you make the same error again twice.
A parent in the yaml file cannot have a value.
when you remove(or comment) Canada from these lines, it will parse properly.
british_columbia: 'Canada'
name: 'british columbia'
country: 'Canada'
saskatchewan: #'Canada'
name: 'saskatchewan'
country: 'Canada'
Is it possible to upsert into a mongodb collection with a JSON/hash of fields, but instead of using the _id ObjectId field, to use a different indexed field such as external_id?
I am using it to update some items that I receive from a feed on a daily basis, and as such, the feed items don't contain my internal ID.
Yes, it is possible to upsert with a custom id in Mongoid, but only in 3.0.0.rc circa June 27, 2012.
app/models/item.rb
class Item
include Mongoid::Document
field :external_id, type: String
field :_id, type: String, default: ->{ external_id }
field :text, type: String
end
test/unit/item_test.rb
require 'test_helper'
class ItemTest < ActiveSupport::TestCase
def setup
Item.delete_all
end
test "external id" do
Item.new( text: 'Lorem ipsum' ).upsert
Item.new( external_id: 'an external id', text: 'dolor sit amet' ).upsert
puts Item.all.to_a.collect{|item|item.inspect}
end
end
output
Run options: --name=test_external_id
# Running tests:
#<Item _id: 4ff202501f98ce8202c03268, _type: nil, external_id: nil, text: "Lorem ipsum">
#<Item _id: an external id, _type: nil, external_id: "an external id", text: "dolor sit amet">
.
Finished tests in 0.028232s, 35.4208 tests/s, 0.0000 assertions/s.
1 tests, 0 assertions, 0 failures, 0 errors, 0 skips
To do this you will have to install from github, visit and clone from
https://github.com/mongoid/mongoid
bundle install
bundle exec rake install
Here's the link to the commit that makes this possible.
https://github.com/mongoid/mongoid/commit/3062363bad3ab947d7689502d6805652b20e89a0
I have a strange error in an admin module created by the admin generator:
My model has the following shema:
StmtcHelp:
columns:
module: { type: string(255) }
action: { type: string(255) }
content: { type: string(10000) }
translated: { type: boolean, notnull: true, default: false }
actAs:
Timestampable: ~
I18n:
fields: [content, translated]
My generator.yml:
generator:
class: sfDoctrineGenerator
param:
model_class: stmtcHelp
theme: admin
non_verbose_templates: true
with_show: false
singular: ~
plural: ~
route_prefix: stmtc_help
with_doctrine_route: true
actions_base_class: sfActions
config:
actions:
_delete:
credentials: [is_super_admin]
_new:
credentials: [is_super_admin]
_create:
credentials: [is_super_admin]
fields: ~
list:
title: Inline Help
display: [ module, action, updated_at ]
filter:
display: [ module, action ]
form: ~
edit: ~
new: ~
Now I clear the cache and load the stmtc_help/index action, I get this error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 's.content' in 'field list'.
Failing Query: "SELECT s.id AS s__id, s.module AS s__module, s.action AS s__action,
s.content AS s__content, s.translated AS s__translated, s.created_at AS s__created_at,
s.updated_at AS s__updated_at FROM stmtc_help s LIMIT 20"
It seems that Doctrine don't recognize my model as I18n.
But if I reload the page, the error disappear, all works fine.
Does anybody have had this kind of issue? What am I missing?
Thanks for any help!
I had exactly the same problem.
Your model_class parameter in generator.yml is set to stmtcHelp but your model name is StmtcHelp (the first letter is uppercase). Fix this one and check routing.yml for the same problem.
In my case I had my model misspelled only in routing.yml and it caused the same Column not found error.
I tried the following:
es:
activerecord:
attributes:
name: Nombre
And it did not work.
But the following do work:
es:
activerecord:
attributes:
person:
name: Nombre
Which is the correct way to define default attributes across models?
Also I'm using Formtastic and Active Admin.
Move the common attributes up one level:
es:
attributes:
name: Nombre
activerecord:
attributes:
user:
birthday: Etc
Example
this is how im doing. Not perfect but will do the job.
activerecord:
attributes:
attribute_commons: &commons
name: Nome
description: Descrição
user:
<<: *commons
role:
<<: *commons
level: Nível
product:
<<: *commons
size: Tamanho
If you are using yaml to store your tranlation, you should look for aliases and anchors in the yaml references :
http://yaml.org/spec/1.2/spec.html
but it is not perfect at all. eg :
bill-to: &id001
street: |
123 Tornado Alley
Suite 16
city: East Centerville
state: KS
ship-to: *id001